Created
August 27, 2018 07:11
-
-
Save marhoily/4fe3eba15799703200d68a6d4fab7005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FakeItEasy; | |
using Xunit; | |
namespace DesignPatters | |
{ | |
public sealed class Pattern1 | |
{ | |
public interface IAmericanSocket { void GetPower(); } | |
public interface IEuropeanSocket { void RetrievePower(); } | |
public sealed class EuropeanDevice { | |
public void Plug(IEuropeanSocket socket) | |
=> socket.RetrievePower(); | |
} | |
sealed class AmericanToEuropean : IEuropeanSocket | |
{ | |
private readonly IAmericanSocket _socket; | |
public AmericanToEuropean(IAmericanSocket socket) { | |
_socket = socket; | |
} | |
public void RetrievePower() => _socket.GetPower(); | |
} | |
private readonly EuropeanDevice _europeanDevice = new EuropeanDevice(); | |
[Fact] | |
public void TestAmericanToEuropean() | |
{ | |
var americanSocket = A.Fake<IAmericanSocket>(); | |
_europeanDevice.Plug(new AmericanToEuropean(americanSocket)); | |
A.CallTo(() => americanSocket.GetPower()) | |
.MustHaveHappened(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment