示例#1
0
        public async Task EventMessageServiceCreateAsyncReturnsAlreadyReportedWhenAlreadyExists()
        {
            // arrange
            var existingContentPageModel = A.Fake <ContentPageModel>();
            var contentPageModel         = A.Fake <ContentPageModel>();

            contentPageModel.PageLocations = new List <PageLocationModel>
            {
                new PageLocationModel(),
            };

            var expectedResult = HttpStatusCode.AlreadyReported;

            A.CallTo(() => fakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(existingContentPageModel);

            var eventMessageService = new EventMessageService <ContentPageModel>(fakeLogger, fakeContentPageService);

            // act
            var result = await eventMessageService.CreateAsync(contentPageModel).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.Equals(result, expectedResult);
        }
        public async Task EventMessageServiceCreateAsyncReturnsBadRequestWhenNullSupplied()
        {
            // arrange
            CmsApiSharedContentModel?contentPageModel = null;
            var expectedResult = HttpStatusCode.BadRequest;

            var eventMessageService = new EventMessageService <CmsApiSharedContentModel>(fakeLogger, fakeDcoumentService);

            // act
            var result = await eventMessageService.CreateAsync(contentPageModel).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeDcoumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeDcoumentService.UpsertAsync(A <CmsApiSharedContentModel> .Ignored)).MustNotHaveHappened();
            A.Equals(result, expectedResult);
        }
        public async Task EventMessageServiceCreateAsyncReturnsSuccess()
        {
            // arrange
            CmsApiSharedContentModel?existingContentPageModel = null;
            var contentPageModel = A.Fake <CmsApiSharedContentModel>();
            var expectedResult   = HttpStatusCode.OK;

            A.CallTo(() => fakeDcoumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(existingContentPageModel);
            A.CallTo(() => fakeDcoumentService.UpsertAsync(A <CmsApiSharedContentModel> .Ignored)).Returns(expectedResult);

            var eventMessageService = new EventMessageService <CmsApiSharedContentModel>(fakeLogger, fakeDcoumentService);

            // act
            var result = await eventMessageService.CreateAsync(contentPageModel).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeDcoumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDcoumentService.UpsertAsync(A <CmsApiSharedContentModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.Equals(result, expectedResult);
        }