Esempio n. 1
0
        public async Task Executes_subsequent_code_only_if_original_boolean_Outcome_is_true_Async()
        {
            var truthy = new Outcome <bool>(true).ForAsync();
            var falsy  = new Outcome <bool>(false).ForAsync();

            var mapper = A.Fake <Func <bool, Task <string> > >();
            var tapper = A.Fake <Func <string, Task> >();

            A.CallTo(() => mapper.Invoke(A <bool> .Ignored)).Returns("Invoked!");

            var truthySeq = await truthy
                            .Filter()
                            .Map(mapper)
                            .Tap(tapper);

            truthySeq.IsSuccessful.Should().BeTrue();
            A.CallTo(() => mapper.Invoke(true)).MustHaveHappenedOnceExactly();
            A.CallTo(() => tapper.Invoke("Invoked!")).MustHaveHappenedOnceExactly();

            Fake.ClearRecordedCalls(mapper);
            Fake.ClearRecordedCalls(tapper);

            var falsySeq = await falsy
                           .Filter()
                           .Map(mapper)
                           .Tap(tapper);

            falsySeq.IsSuccessful.Should().BeFalse();
            falsySeq.FailureOrNull().Should().BeAssignableTo <ExpectationFailure>();
            A.CallTo(() => mapper.Invoke(A <bool> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => tapper.Invoke(A <string> .Ignored)).MustNotHaveHappened();
        }
        public void StatusUpdate_Exception()
        {
            // arrange
            SetupMockControlFileFor2Podcasts();
            SetupEpisodesFor2Podcasts();
            ViewModel.Initialise();
            ViewModel.FindEpisodesToDownload();
            var testException  = new Exception("TEST EXCEPTION");
            var syncItemMocker = SetupFireStatusEvent(EPISODE_1_ID, StatusUpdateLevel.Error, false, testException, "test exception");

            Fake.ClearRecordedCalls(MockStatusAndProgressMessageStore);
            Fake.ClearRecordedCalls(MockAnalyticsEngine);

            // act
            ViewModel.DownloadAllPodcastsWithoutNetworkCheck().Wait();

            // assert
            A.CallTo(() => MockCrashReporter.LogNonFatalException(testException)).MustHaveHappened(1, Times.Exactly);
            A.CallTo(() => MockStatusAndProgressMessageStore.StoreMessage(
                         A <Guid> .That.Matches(g => g.ToString() == EPISODE_1_ID.ToString()),
                         A <string> .That.Matches(s => s == "test exception")))
            .MustHaveHappened(1, Times.Exactly);
            A.CallTo(() => MockStatusAndProgressMessageStore.StoreMessage(
                         A <Guid> .That.Matches(g => g.ToString() == EPISODE_1_ID.ToString()),
                         A <string> .That.Matches(s => s == "System.Exception: TEST EXCEPTION")))
            .MustHaveHappened(1, Times.Exactly);
            Assert.AreEqual("test exception", ObservedResults.LastUpdateStatusMessage, "message");
            Assert.AreEqual(syncItemMocker.GetMockedSyncItem(), ObservedResults.LastUpdateStatusItem, "item");
            Assert.AreEqual(Status.Error, ObservedResults.LastUpdateStatus, "status");
            A.CallTo(MockAnalyticsEngine).MustNotHaveHappened();
        }
 public void Cleanup()
 {
     Fake.ClearRecordedCalls(centresDataService);
     Fake.ClearRecordedCalls(mapsApiHelper);
     Fake.ClearRecordedCalls(logger);
     Fake.ClearRecordedCalls(imageResizeService);
 }
Esempio n. 4
0
        public async Task It_can_filter_using_a_predicate()
        {
            var hundred  = new Outcome <int>(100).ForAsync();
            var thousand = new Outcome <int>(1000).ForAsync();

            var mapper = A.Fake <Func <int, Task <string> > >();
            var tapper = A.Fake <Func <string, Task> >();

            A.CallTo(() => mapper.Invoke(A <int> .Ignored)).Returns("Invoked!");

            var truthySeq = await hundred
                            .Filter(h => h == 100)
                            .Map(mapper)
                            .Tap(tapper);

            truthySeq.IsSuccessful.Should().BeTrue();
            A.CallTo(() => mapper.Invoke(100)).MustHaveHappenedOnceExactly();
            A.CallTo(() => tapper.Invoke("Invoked!")).MustHaveHappenedOnceExactly();

            Fake.ClearRecordedCalls(mapper);
            Fake.ClearRecordedCalls(tapper);

            var falsySeq = await thousand
                           .Filter(t => t == 100)
                           .Map(mapper)
                           .Tap(tapper);

            falsySeq.IsSuccessful.Should().BeFalse();
            falsySeq.FailureOrNull().Should().BeAssignableTo <ExpectationFailure>();
            A.CallTo(() => mapper.Invoke(A <int> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => tapper.Invoke(A <string> .Ignored)).MustNotHaveHappened();
        }
Esempio n. 5
0
 protected void ClearFakesRecordedCalls()
 {
     Fake.ClearRecordedCalls(EntityRepository);
     Fake.ClearRecordedCalls(PermissionRepo);
     Fake.ClearRecordedCalls(InventoryRepo);
     Fake.ClearRecordedCalls(ShopRepo);
     Fake.ClearRecordedCalls(EventTransmitter);
 }
        protected void InitializeSystemUnderTest(int cacheTimeoutInMinutes)
        {
            _systemUnderTest = new CachedSecurityRepository(_securityContextFactory, cacheTimeoutInMinutes);

            // Should hit the database on construction
            A.CallTo(() => _securityContextFactory.CreateContext()).MustHaveHappened(1, Times.Exactly);
            Fake.ClearRecordedCalls(_securityContextFactory);
        }
Esempio n. 7
0
        public void When_ExistingPasswordIsRemoved_Then_PasswordsAreSaved()
        {
            _manager.SavePassword("foo", "bar", new SecureString());
            Fake.ClearRecordedCalls(_store);
            _manager.RemovePassword("foo", "bar");

            A.CallTo(() => _store.Save(A <PasswordDictionary> ._)).MustHaveHappened(1, Times.Exactly);
        }
Esempio n. 8
0
 public static void Clear()
 {
     if (logger == null)
     {
         return;
     }
     Fake.ClearConfiguration(logger);
     Fake.ClearRecordedCalls(logger);
 }
Esempio n. 9
0
        protected void InitializeSystemUnderTest(int cacheTimeoutInMinutes)
        {
            _systemUnderTest = new CachedSecurityRepository(_securityContextFactory, cacheTimeoutInMinutes);
            _systemUnderTest.GetClaimsForClaimSet("ClaimSet");

            // Should hit the database after calling a getter because it has lazy initialization
            A.CallTo(() => _securityContextFactory.CreateContext()).MustHaveHappened(1, Times.Exactly);
            Fake.ClearRecordedCalls(_securityContextFactory);
        }
Esempio n. 10
0
        public void ClearRecordedCalls_should_be_guarded()
        {
            // Arrange

            // Act

            // Assert
            Expression <Action> call = () => Fake.ClearRecordedCalls(A.Dummy <object>());

            call.Should().BeNullGuarded();
        }
Esempio n. 11
0
    public void Compute_cells_fire_callbacks()
    {
        var sut       = new Reactor();
        var input     = sut.CreateInputCell(1);
        var output    = sut.CreateComputeCell(new[] { input }, inputs => inputs[0] + 1);
        var callback1 = A.Fake <EventHandler <int> >();

        output.Changed += callback1;
        input.Value     = 3;
        A.CallTo(() => callback1.Invoke(A <object> ._, 4)).MustHaveHappenedOnceExactly();
        Fake.ClearRecordedCalls(callback1);
    }
Esempio n. 12
0
        public void ApplyCommand_ShouldCallMockServerUpdateMappingsAndShouldSaveMappings()
        {
            var expectedMappings = MappingInfoViewModelTestUtils.SomeMappings();

            A.CallTo(() => _mappingsProvider.LoadMappings()).Returns(ToPersistableMappings(expectedMappings));
            _mainWindowViewModel = new MainWindowViewModel(_mockServer, _mappingsProvider);
            Fake.ClearRecordedCalls(_mockServer);

            ExecuteApplyCommand();

            A.CallTo(() => _mockServer.UpdateMappings(_mainWindowViewModel.Mappings)).MustHaveHappenedOnceExactly()
            .Then(A.CallTo(() => _mappingsProvider.SaveMappings(ShouldMatchInfoMappingsViewModel(_mainWindowViewModel.Mappings))).MustHaveHappenedOnceExactly());
        }
Esempio n. 13
0
        public void WhenAlreadyMarkedAsChecked_AndHasOccupant_ShouldNotReportHitToOccupant()
        {
            var occupantDouble = CreateFakeShip();
            var subject        = new Position(DummyCoordinates, occupantDouble);

            subject.MarkAsChecked();

            Fake.ClearRecordedCalls(occupantDouble);

            subject.MarkAsChecked();

            A.CallTo(() => occupantDouble.ReportHit()).MustNotHaveHappened();
        }
Esempio n. 14
0
        public void SetUp()
        {
            _predicates.Clear();
            _predicates.Add(x => false);
            Fake.ClearConfiguration(_responseFactory);
            Fake.ClearRecordedCalls(_responseFactory);
            Fake.ClearConfiguration(_handler);
            Fake.ClearRecordedCalls(_handler);

            _sut = new WebConfiguration(
                _predicates,
                _responseFactory,
                _handler);
        }
Esempio n. 15
0
    public void Callback_cells_only_fire_on_change()
    {
        var sut       = new Reactor();
        var input     = sut.CreateInputCell(1);
        var output    = sut.CreateComputeCell(new[] { input }, inputs => inputs[0] < 3 ? 111 : 222);
        var callback1 = A.Fake <EventHandler <int> >();

        output.Changed += callback1;
        input.Value     = 2;
        A.CallTo(() => callback1.Invoke(A <object> ._, A <int> ._)).MustNotHaveHappened();
        input.Value = 4;
        A.CallTo(() => callback1.Invoke(A <object> ._, 222)).MustHaveHappenedOnceExactly();
        Fake.ClearRecordedCalls(callback1);
    }
Esempio n. 16
0
        public void CalledUpdateUsingFirstNumber()
        {
            var fakeService = _fakeContext.GetOrganizationService();

            Fake.ClearRecordedCalls(fakeService);

            _doubleUpdater.UpdateWithTwoNumbers(FirstUpdatedNumber, SecondUpdatedNumber);

            var calls = Fake.GetCalls(fakeService).ToList();

            Assert.Contains(calls, call =>
                            call.Method.Name == "Update" &&
                            call.GetArgument <Entity>(0)?[DoubleUpdater.AttributeName] as int? == FirstUpdatedNumber
                            );
        }
Esempio n. 17
0
    public void Callbacks_should_only_be_called_once_even_if_multiple_dependencies_change()
    {
        var sut       = new Reactor();
        var input     = sut.CreateInputCell(1);
        var plusOne   = sut.CreateComputeCell(new[] { input }, inputs => inputs[0] + 1);
        var minusOne1 = sut.CreateComputeCell(new[] { input }, inputs => inputs[0] - 1);
        var minusOne2 = sut.CreateComputeCell(new[] { minusOne1 }, inputs => inputs[0] - 1);
        var output    = sut.CreateComputeCell(new[] { plusOne, minusOne2 }, inputs => inputs[0] * inputs[1]);
        var callback1 = A.Fake <EventHandler <int> >();

        output.Changed += callback1;
        input.Value     = 4;
        A.CallTo(() => callback1.Invoke(A <object> ._, 10)).MustHaveHappenedOnceExactly();
        Fake.ClearRecordedCalls(callback1);
    }
Esempio n. 18
0
    public void Callbacks_can_fire_from_multiple_cells()
    {
        var sut       = new Reactor();
        var input     = sut.CreateInputCell(1);
        var plusOne   = sut.CreateComputeCell(new[] { input }, inputs => inputs[0] + 1);
        var minusOne  = sut.CreateComputeCell(new[] { input }, inputs => inputs[0] - 1);
        var callback1 = A.Fake <EventHandler <int> >();

        plusOne.Changed += callback1;
        var callback2 = A.Fake <EventHandler <int> >();

        minusOne.Changed += callback2;
        input.Value       = 10;
        A.CallTo(() => callback1.Invoke(A <object> ._, 11)).MustHaveHappenedOnceExactly();
        Fake.ClearRecordedCalls(callback1);
        A.CallTo(() => callback2.Invoke(A <object> ._, 9)).MustHaveHappenedOnceExactly();
        Fake.ClearRecordedCalls(callback2);
    }
Esempio n. 19
0
        public static void ClearRecordedCalls(IFoo fake)
        {
            "Given a Fake"
            .x(() => fake = A.Fake <IFoo>());

            "And I make several calls to the Fake"
            .x(() =>
            {
                fake.AMethod();
                fake.AnotherMethod();
                fake.AnotherMethod("houseboat");
            });

            "When I clear the recorded calls"
            .x(() => Fake.ClearRecordedCalls(fake));

            "Then the recorded call list is empty"
            .x(() => Fake.GetCalls(fake).Should().BeEmpty());
        }
        public void ProgressUpdate_UpdatesProgress_Not_At_11()
        {
            // arrange
            SetupMockControlFileFor2Podcasts();
            SetupEpisodesFor2Podcasts();
            ViewModel.Initialise();
            ViewModel.FindEpisodesToDownload();
            var syncItemMocker = SetupFireProgressEvent(EPISODE_1_ID, 11);

            Fake.ClearRecordedCalls(MockStatusAndProgressMessageStore);

            // act
            ViewModel.DownloadAllPodcastsWithoutNetworkCheck().Wait();

            // assert
            A.CallTo(() => MockCrashReporter.LogNonFatalException(A <Exception> .Ignored)).MustNotHaveHappened();
            A.CallTo(MockStatusAndProgressMessageStore).MustNotHaveHappened();
            Assert.AreEqual(0, ObservedResults.LastUpdatePercentage, "percentage");
            Assert.IsNull(ObservedResults.LastUpdatePercentageItem, "item");
        }
Esempio n. 21
0
        public async Task AuthorisationRequiredForAllEndpoints()
        {
            _client.DefaultRequestHeaders.Add("oidc_claim_email", "value");
            _client.DefaultRequestHeaders.Add("oidc_claim_given_name", "value");
            _client.DefaultRequestHeaders.Add("oidc_claim_family_name", "value");

            Assert.NotZero(Endpoints.Count, "Endpoints are discovered");

            foreach ((string, string)endpoint in Endpoints)
            {
                HttpMethod         httpMethod = new HttpMethod(endpoint.Item1);
                string             url        = endpoint.Item2.Replace("{domain}", "digital.ncsc.gov.uk");
                HttpRequestMessage request    = new HttpRequestMessage(httpMethod, url);

                HttpResponseMessage response = await _client.SendAsync(request);

                Assert.AreEqual(1, Fake.GetCalls(_mailCheckAuthorisationService).Count(), "The request should authorise once");
                Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "The request should be forbidden");
                Fake.ClearRecordedCalls(_mailCheckAuthorisationService);
            }
        }
Esempio n. 22
0
        public override void Dispose()
        {
            ContainerBuilder builder = GetContainerBuidler();

            builder.ComponentRegistryBuilder.Registered -= OnComponentRegistered;

            if (Objects != null)
            {
                foreach (object obj in Objects.Where(obj => Fake.IsFake(obj)))
                {
                    Fake.ClearConfiguration(obj);
                    Fake.ClearRecordedCalls(obj);
                }

                Objects.Dispose();
            }

            Objects = null;

            base.Dispose();
        }
        public async Task AuthorisationRequiredForAllEndpoints()
        {
            _client.DefaultRequestHeaders.Add("oidc_claim_email", "value");
            _client.DefaultRequestHeaders.Add("oidc_claim_given_name", "value");
            _client.DefaultRequestHeaders.Add("oidc_claim_family_name", "value");

            Assert.NotZero(_endpointHelper.EndpointDescriptions.Count, "Endpoints are discovered");

            foreach (var endpoint in _endpointHelper.EndpointDescriptions)
            {
                HttpMethod         httpMethod = new HttpMethod(endpoint.Method);
                string             url        = endpoint.UrlTemplate;
                HttpRequestMessage request    = new HttpRequestMessage(httpMethod, url);

                HttpResponseMessage response = await _client.SendAsync(request);

                Assert.AreEqual(1, Fake.GetCalls(_mailCheckAuthorisationService).Count(), "The request should authorise once");
                Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "The request should be forbidden");
                Fake.ClearRecordedCalls(_mailCheckAuthorisationService);
            }
        }
Esempio n. 24
0
    public void Callbacks_can_be_added_and_removed()
    {
        var sut       = new Reactor();
        var input     = sut.CreateInputCell(11);
        var output    = sut.CreateComputeCell(new[] { input }, inputs => inputs[0] + 1);
        var callback1 = A.Fake <EventHandler <int> >();

        output.Changed += callback1;
        var callback2 = A.Fake <EventHandler <int> >();

        output.Changed += callback2;
        input.Value     = 31;
        A.CallTo(() => callback1.Invoke(A <object> ._, 32)).MustHaveHappenedOnceExactly();
        Fake.ClearRecordedCalls(callback1);
        A.CallTo(() => callback2.Invoke(A <object> ._, 32)).MustHaveHappenedOnceExactly();
        Fake.ClearRecordedCalls(callback2);
        output.Changed -= callback1;
        var callback3 = A.Fake <EventHandler <int> >();

        output.Changed += callback3;
        input.Value     = 41;
        A.CallTo(() => callback1.Invoke(A <object> ._, A <int> ._)).MustNotHaveHappened();
    }
        public void ProgressUpdate_UpdatesProgress_At_10()
        {
            // arrange
            SetupMockControlFileFor2Podcasts();
            SetupEpisodesFor2Podcasts();
            ViewModel.Initialise();
            ViewModel.FindEpisodesToDownload();
            var syncItemMocker = SetupFireProgressEvent(EPISODE_1_ID, 10);

            Fake.ClearRecordedCalls(MockStatusAndProgressMessageStore);

            // act
            ViewModel.DownloadAllPodcastsWithoutNetworkCheck().Wait();

            // assert
            A.CallTo(() => MockCrashReporter.LogNonFatalException(A <Exception> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => MockStatusAndProgressMessageStore.StoreMessage(
                         A <Guid> .That.Matches(g => g.ToString() == EPISODE_1_ID.ToString()),
                         A <string> .That.Matches(s => s == "EpisodeTitle (10 bytes of 100 bytes) 10%")))
            .MustHaveHappened(1, Times.Exactly);
            Assert.AreEqual(10, ObservedResults.LastUpdatePercentage, "percentage");
            Assert.AreEqual(syncItemMocker.GetMockedSyncItem(), ObservedResults.LastUpdatePercentageItem, "item");
        }
        public void StatusUpdate_StatusMessageVerboseDoesNotDisplay()
        {
            // arrange
            SetupMockControlFileFor2Podcasts();
            SetupEpisodesFor2Podcasts();
            ViewModel.Initialise();
            ViewModel.FindEpisodesToDownload();
            var syncItemMocker = SetupFireStatusEvent(EPISODE_1_ID, StatusUpdateLevel.Verbose, false, null, "test verbose");

            Fake.ClearRecordedCalls(MockStatusAndProgressMessageStore);
            Fake.ClearRecordedCalls(MockAnalyticsEngine);

            // act
            ViewModel.DownloadAllPodcastsWithoutNetworkCheck().Wait();

            // assert
            A.CallTo(() => MockCrashReporter.LogNonFatalException(A <Exception> .Ignored)).MustNotHaveHappened();
            Assert.IsNull(ObservedResults.LastUpdateStatusMessage, "message");
            Assert.IsNull(ObservedResults.LastUpdateStatusItem, "item");
            Assert.AreEqual(Status.OK, ObservedResults.LastUpdateStatus, "status");
            A.CallTo(MockStatusAndProgressMessageStore).MustNotHaveHappened();
            A.CallTo(MockAnalyticsEngine).MustNotHaveHappened();
        }
Esempio n. 27
0
 public void SetUp()
 {
     Fake.ClearRecordedCalls(_fakeQuery);
     Fake.ClearRecordedCalls(_fakeCommand);
 }
Esempio n. 28
0
 public void ToggleOwnAutoStart_ShowsNoErrorMessageIfNoError() {
     app.ToggleOwnAutoStart().Wait();
     A.CallTo(() => MessageService.ShowError(A<string>.Ignored, A<Exception>.Ignored)).MustNotHaveHappened();
     Fake.ClearRecordedCalls(MessageService);
 }
Esempio n. 29
0
 public void ToggleOwnAutoStart_ShowsErrorMessageOnError() {
     A.CallTo(() => AutoStartService.ToggleOwnAutoStart()).Throws(new Exception());
     app.ToggleOwnAutoStart().Wait();
     A.CallTo(() => MessageService.ShowError(A<string>.Ignored, A<Exception>.Ignored)).MustHaveHappened();
     Fake.ClearRecordedCalls(MessageService);
 }
Esempio n. 30
0
 public void EachSetup()
 {
     Fake.ClearRecordedCalls(_expectationConfigurator);
     _spec = null;
 }