public void TryValidateModelReturnsArgumentNullException()
        {
            //Arrange
            var service = new StaticContentReloadService(fakeLogger, fakeMapper, fakeStaticContentDocumentService, fakeCmsApiService, fakeCmsApiClientOptions);
            StaticContentItemModel model = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => service.TryValidateModel(model));
        }
        public void TryValidateModelForValidAndInvalid(StaticContentItemModel model, bool expectedResult)
        {
            //Arrange
            var service = new StaticContentReloadService(fakeLogger, fakeMapper, fakeStaticContentDocumentService, fakeCmsApiService, fakeCmsApiClientOptions);

            //Act
            var result = service.TryValidateModel(model);

            //Assert
            Assert.Equal(expectedResult, result);
        }
        public async Task ReloadIsCancelled()
        {
            //Arrange
            var cancellationToken = new CancellationToken(true);
            var service           = new StaticContentReloadService(fakeLogger, fakeMapper, fakeStaticContentDocumentService, fakeCmsApiService, fakeCmsApiClientOptions);

            //Act
            await service.Reload(cancellationToken).ConfigureAwait(false);

            //Assert
            A.CallTo(() => fakeCmsApiService.GetItemAsync <StaticContentItemApiDataModel>(A <string> .Ignored, A <Guid> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeMapper.Map <StaticContentItemModel>(A <StaticContentItemApiDataModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeStaticContentDocumentService.UpsertAsync(A <StaticContentItemModel> .Ignored)).MustNotHaveHappened();

            Assert.True(true);
        }
Esempio n. 4
0
        public async Task ReloadSharedContentWithValidationErrors()
        {
            //Arrange
            var cancellationToken = new CancellationToken(false);
            var service           = new StaticContentReloadService(fakeLogger, fakeMapper, fakeStaticContentDocumentService, fakeCmsApiService, fakeCmsApiClientOptions);
            StaticContentItemApiDataModel staticContentItemApiDataModel = null;
            var dummyStaticContentItemModel = A.Dummy <StaticContentItemModel>();

            A.CallTo(() => fakeCmsApiService.GetItemAsync <StaticContentItemApiDataModel>(A <string> .Ignored, A <Guid> .Ignored)).Returns(staticContentItemApiDataModel);
            A.CallTo(() => fakeMapper.Map <StaticContentItemModel>(A <StaticContentItemApiDataModel> .Ignored)).Returns(dummyStaticContentItemModel);

            //Act
            await service.ReloadSharedContent(cancellationToken).ConfigureAwait(false);

            //Assert
            A.CallTo(() => fakeCmsApiService.GetItemAsync <StaticContentItemApiDataModel>(A <string> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceOrMore();
            A.CallTo(() => fakeMapper.Map <StaticContentItemModel>(A <StaticContentItemApiDataModel> .Ignored)).MustHaveHappenedOnceOrMore();
            A.CallTo(() => fakeStaticContentDocumentService.UpsertAsync(A <StaticContentItemModel> .Ignored)).MustNotHaveHappened();

            Assert.True(true);
        }
        public async Task ReloadSharedContentIsSuccessful()
        {
            //Arrange
            var cancellationToken = new CancellationToken(false);
            var service           = new StaticContentReloadService(fakeLogger, fakeMapper, fakeStaticContentDocumentService, fakeCmsApiService, fakeCmsApiClientOptions);
            var dummyStaticContentItemApiDataModel = A.Dummy <StaticContentItemApiDataModel>();
            var staticContentItemModel             = BuildValidStaticContentItemModel();

            A.CallTo(() => fakeStaticContentDocumentService.PurgeAsync()).Returns(true);
            A.CallTo(() => fakeCmsApiService.GetItemAsync <StaticContentItemApiDataModel>(A <string> .Ignored, A <Guid> .Ignored)).Returns(dummyStaticContentItemApiDataModel);
            A.CallTo(() => fakeMapper.Map <StaticContentItemModel>(A <StaticContentItemApiDataModel> .Ignored)).Returns(staticContentItemModel);
            A.CallTo(() => fakeStaticContentDocumentService.UpsertAsync(A <StaticContentItemModel> .Ignored)).Returns(HttpStatusCode.OK);

            //Act
            await service.ReloadSharedContent(cancellationToken).ConfigureAwait(false);

            //Assert
            A.CallTo(() => fakeStaticContentDocumentService.PurgeAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeCmsApiService.GetItemAsync <StaticContentItemApiDataModel>(A <string> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceOrMore();
            A.CallTo(() => fakeMapper.Map <StaticContentItemModel>(A <StaticContentItemApiDataModel> .Ignored)).MustHaveHappenedOnceOrMore();
            A.CallTo(() => fakeStaticContentDocumentService.UpsertAsync(A <StaticContentItemModel> .Ignored)).MustHaveHappenedOnceOrMore();

            Assert.True(true);
        }