public void Initialize() { fakeStories = new Story[] { new Story { Message = "First story", PostedOn = new DateTime(2000, 1, 1, 15, 1, 0) }, new Story { Message = "Second story", PostedOn = new DateTime(2000, 1, 1, 15, 5, 0) } }; //Creates a fake ITimelineReaderService with a liked observer in order to //assert that the SUT relies on it timelineReaderServiceObserver = new StubObserver(); timelineReaderService = new Contracts.Interfaces.Fakes.StubITimelineReaderService { InstanceObserver = timelineReaderServiceObserver, GetTimelineString = userName => fakeStories }; storyFormatterObserver = new StubObserver(); storyFormatter = new Contracts.Interfaces.Fakes.StubIEntityFormatter<Story> { InstanceObserver = storyFormatterObserver, FormatT0 = story => story.Message }; sut = new ReadCommand(timelineReaderService, storyFormatter); }
public void Initialize() { //Initializing observers readCommandObserver = new StubObserver(); postCommandObserver = new StubObserver(); wallCommandObserver = new StubObserver(); //Initializing fake commands with arbitrary signatures. //Each one is linked to its observer in order to check //whether the requests are properly routed readCommand = new Contracts.Interfaces.Fakes.StubICommand { // command signature: {UserName} SignatureGet = () => @"^([^\s][A-Za-z0-9-_]+)$", InstanceObserver = readCommandObserver }; postCommand = new Contracts.Interfaces.Fakes.StubICommand { // command signature: {UserName} -> {Message} SignatureGet = () => @"^([^\s][A-Za-z0-9-_]+) -> (.+)$", InstanceObserver = postCommandObserver }; wallCommand = new Contracts.Interfaces.Fakes.StubICommand { // command signature: {UserName} Wall SignatureGet = () => @"^([^\s][A-Za-z0-9-_]+) Wall$", InstanceObserver = wallCommandObserver }; }
public void Initialize() { fakeAggregatedStories = new AggregatedStory[] { new AggregatedStory { Story = new Story { Message = "First story", PostedOn = new DateTime(2000, 1, 1, 15, 1, 0) }}, new AggregatedStory { Story = new Story { Message = "Second story", PostedOn = new DateTime(2000, 1, 1, 15, 5, 0) }} }; //Creates a fake IAggregatorService with a liked observer in order to //assert that the SUT relies on it aggregatorServiceObserver = new StubObserver(); aggregatorService = new Contracts.Interfaces.Fakes.StubIAggregatorService { InstanceObserver = aggregatorServiceObserver, GetAggregatedStoriesString = userName => fakeAggregatedStories }; aggregatedStoryFormatterObserver = new StubObserver(); aggregatedStoryFormatter = new Contracts.Interfaces.Fakes.StubIEntityFormatter<AggregatedStory> { InstanceObserver = aggregatedStoryFormatterObserver, FormatT0 = aggregatedStory => aggregatedStory.Story.Message }; sut = new WallCommand(aggregatorService, aggregatedStoryFormatter); }
public void Initialize() { //Creates a fake ITimelineWriterService with a liked observer in order to //assert that the SUT relies on it timelineWriterServiceObserver = new StubObserver(); timelineWriterService = new Contracts.Interfaces.Fakes.StubITimelineWriterService { InstanceObserver = timelineWriterServiceObserver }; sut = new PostCommand(timelineWriterService); }
public void Initialize() { //Creates a fake IFollowerService with a liked observer in order to //assert that the SUT relies on it followerServiceObserver = new StubObserver(); followerService = new Contracts.Interfaces.Fakes.StubIFollowerService { InstanceObserver = followerServiceObserver }; sut = new FollowsCommand(followerService); }
public void TestMethod3() { //Arrange var stubLogger = new StubILogger {ShouldLog = () => true}; var sut = new ClassA(); var observer = new StubObserver(); stubLogger.InstanceObserver = observer; //Act sut.GetName(stubLogger); var calls = observer.GetCalls(); }
public FakeOrganzationService(IOrganizationService realService) { Observer = new StubObserver(); this.InstanceObserver = Observer; CallCount = 0; if (realService == null) { WireUpFakes(); } else { WireUpRealService(realService); } }
public void GetEventName_Test_Fakes() { //arrange var stubLogger = new StubILogger { IsLoggerEnabledGet = () => true }; var diagonizeStub = new DiagonizeStubs(); var observer = new StubObserver(); stubLogger.InstanceObserver = observer; //act diagonizeStub.GetEventName(stubLogger); var calls = observer.GetCalls(); //assert Assert.IsNotNull(calls); Assert.AreEqual(2, calls.Length); }
public void Initialize() { // Initialize fake user fakeUser = new User { Name = "Alice", Timeline = new List<Story>() }; // Initializes a fake repository that returns the fake user // and attaches an observer to it in order to check if the repository // is correctly called by the TimelineWriterService userRepositoryObserver = new StubObserver(); userRepository = new Contracts.Interfaces.Fakes.StubIRepository<User> { GetOrCreateString = (userName) => fakeUser, InstanceObserver = userRepositoryObserver }; sut = new TimelineWriterService(userRepository); }
public void Test_Stub_Observer_Contains_Valid_Argument_And_Method_Info() { // Arrange var mock = new StubILogWriter(); var stubObserver = new StubObserver(); mock.InstanceObserver = stubObserver; // Act ((ILogWriter)mock).Write("Foo"); // Assert var calls = stubObserver.GetCalls(); CollectionAssert.IsNotEmpty(calls, "Should be at least one call to the observer."); var callInfo = calls[0]; Assert.That(callInfo.GetArguments()[0], Is.EqualTo("Foo"), "Mocked method should be called with 'Foo' argument."); Assert.That(callInfo.StubbedMethod.Name, Is.EqualTo("Write"), "ILogWriter.Write method should be called."); }
/// <summary> /// Gets the calls made to the Execute method of the provided observer /// </summary> /// <param name="observer"></param> /// <returns></returns> private IEnumerable<StubObservedCall> GetExecuteCall(StubObserver observer) { return observer.GetCalls().Where(c => c.StubbedMethod.Name == "Execute"); }