public async Task WhenJsonSourceIsNotValid_HTT500_CanReturnAnEmptyArray()
        {
            //Arrange
            var registrations = new List <OwnerInfo>();

            var stubILogger       = StubHelper.StubILogger <RegistrationController>();
            var stubIFetchService = StubHelper.StubIFetchService;

            stubIFetchService.Setup(x => x.GetRegistrations())
            .Returns(Task.FromResult(registrations));
            var stubIRenderService = StubHelper.StubIRenderService;
            var stubIVewingService = StubHelper.StubIVewingService;

            var testedService = new RegistrationController(stubILogger.Object,
                                                           stubIFetchService.Object,
                                                           stubIVewingService.Object,
                                                           stubIRenderService.Object);

            //Act
            var result = await testedService.GetAll();

            var actual = result as NoContentResult;

            //Assert
            Assert.Equal((int)HttpStatusCode.NoContent, actual.StatusCode);
        }
        public async Task WhenJsonSourceIsValid_CanReturnAllRegistrations()
        {
            //Arrange
            var registrations = FakeModels.Registrations;
            var testViewData  = FakeModels.CatsViewForRender;
            var renderingData = FakeModels.RenderingData;

            var stubILogger       = StubHelper.StubILogger <RegistrationController>();
            var stubIFetchService = StubHelper.StubIFetchService;

            stubIFetchService.Setup(x => x.GetRegistrations())
            .Returns(Task.FromResult(registrations));
            var stubIVewingService = StubHelper.StubIVewingService;

            stubIVewingService.Setup(x => x.ViewRegistrations(It.IsAny <List <OwnerInfo> >(), ViewType.CatsUnderOnwersGender))
            .Returns(testViewData);
            var stubIRenderService = StubHelper.StubIRenderService;

            stubIRenderService.Setup(x => x.RenderRegistrations(It.IsAny <List <ResultFormat> >()))
            .Returns(renderingData);

            var testedService = new RegistrationController(stubILogger.Object,
                                                           stubIFetchService.Object,
                                                           stubIVewingService.Object,
                                                           stubIRenderService.Object);

            //Act
            var result = await testedService.GetAll();

            var actual = result as ContentResult;

            //Assert
            Assert.Equal((int)HttpStatusCode.OK, actual.StatusCode);
        }
        public void WhenPrivateValidRegistrations_CanReturnExceptedView()
        {
            //Arrange
            var registrations = FakeModels.Registrations;
            var testViewType  = ViewType.CatsUnderOnwersGender;

            var stubILogger         = StubHelper.StubILogger <ViewsService>();
            var stubViewingServiceA = StubHelper.StubIViewingService;

            stubViewingServiceA.Setup(x => x.ViewSortType)
            .Returns(testViewType);
            stubViewingServiceA.Setup(x => x.SortRegistrations(It.IsAny <List <OwnerInfo> >()))
            .Returns(FakeModels.CatsViewForRender);
            var stubViewingServiceB = StubHelper.StubIViewingService;

            stubViewingServiceB.Setup(x => x.ViewSortType)
            .Returns(ViewType.DogsUnderOnwersGender);
            stubViewingServiceB.Setup(x => x.SortRegistrations(It.IsAny <List <OwnerInfo> >()))
            .Returns(FakeModels.DogsViewForRender);

            var _viewingServices = new List <IViewingService> {
                stubViewingServiceA.Object, stubViewingServiceB.Object
            };

            var testedService = new ViewsService(stubILogger.Object, _viewingServices);

            //Act
            var actual = testedService.ViewRegistrations(registrations, testViewType);

            //Assert
            //the total items of actaul should be equal to the number of cats in the registration
            Assert.Equal(FakeModels.CatsViewForRender.SelectMany(x => x.Items).ToList().Count,
                         actual.SelectMany(x => x.Items).ToList().Count);
        }
        public void WhenProductIsValid_CanReturnCubicWeight()
        {
            //Arrange
            var product  = FakeModels.TestProduct;
            var settings = new CubicWeightSettings()
            {
                ConversionFactor = 1
            };

            var stubILogger           = StubHelper.StubILogger <CubicWeightService>();
            var stubIExceptionFactory = StubHelper.StubIExceptionFactory;
            var stubIFetchService     = StubHelper.StubIFetchService;

            var testedService = new CubicWeightService(stubILogger.Object,
                                                       stubIExceptionFactory.Object,
                                                       stubIFetchService.Object,
                                                       Options.Create(settings));

            //Act
            var actual = testedService.WeightCalculator(product);

            //Assert
            var weight = product.Size.CubicMetres * settings.ConversionFactor;

            Assert.Equal(weight, actual);
        }
        public void WhenPrivateValidResults_CanRenderToExpectedFormat()
        {
            //Arrange
            var testViewData = FakeModels.CatsViewForRender;

            var stubILogger = StubHelper.StubILogger <RenderService>();

            var testedService = new RenderService(stubILogger.Object);

            //Act
            var actual = testedService.RenderRegistrations(testViewData);

            //Assert
            Assert.Contains("Female", actual);
        }
示例#6
0
        public void WhenPrivateValidRegistrations_CanReturnExceptedCatsView()
        {
            //Arrange
            var registrations = FakeModels.Registrations;

            var stubILogger = StubHelper.StubILogger <CatsUnderOnwersGenderView>();

            var testedService = new CatsUnderOnwersGenderView(stubILogger.Object);

            //Act
            var actual = testedService.SortRegistrations(registrations);

            //Assert
            //the total items of actaul should be equal to the number of cats in the registration
            Assert.Equal(registrations.SelectMany(x => x.Pets).ToList().Count(x => x.Type == PetType.Cat),
                         actual.SelectMany(x => x.Items).ToList().Count);
        }
        public async Task WhenJsonSourceIsNotValid_CanReturnAnEmptyList()
        {
            //Arrange
            List <OwnerInfo> registrations = null;
            var settings = new JsonConsumerSettings();

            var stubILogger           = StubHelper.StubILogger <FetchService>();
            var stubIExceptionFactory = StubHelper.StubIExceptionFactory;
            var stubIRestApiService   = StubHelper.StubIRestApiService;

            stubIRestApiService.Setup(x => x.GetRequestAsync <List <OwnerInfo> >(It.IsAny <string>()))
            .Returns(Task.FromResult(registrations));

            var testedService = new FetchService(stubILogger.Object,
                                                 stubIExceptionFactory.Object,
                                                 stubIRestApiService.Object,
                                                 Options.Create(settings));

            //Act
            var actual = await testedService.GetRegistrations();

            //Assert
            Assert.False(actual.Any());
        }
        public void WhenSizeIsNull_CanReturnZero()
        {
            //Arrange
            var emptyProduct = new Product();
            var settings     = new CubicWeightSettings()
            {
                ConversionFactor = 250
            };

            var stubILogger           = StubHelper.StubILogger <CubicWeightService>();
            var stubIExceptionFactory = StubHelper.StubIExceptionFactory;
            var stubIFetchService     = StubHelper.StubIFetchService;

            var testedService = new CubicWeightService(stubILogger.Object,
                                                       stubIExceptionFactory.Object,
                                                       stubIFetchService.Object,
                                                       Options.Create(settings));

            //Act
            var actual = testedService.WeightCalculator(emptyProduct);

            //Assert
            Assert.Equal(0, actual);
        }