Exemplo n.º 1
0
        public async Task BrandsController_GetAll_Success()
        {
            var brands = new List <BrandCreateRequest> {
                new BrandCreateRequest {
                    Name = "Test brand1"
                },
                new BrandCreateRequest {
                    Name = "Test brand2"
                }
            };

            var controller = new BrandsController(_fixture.BrandService);

            foreach (var brand in brands)
            {
                await controller.Post(brand);
            }

            var result = await controller.GetAll();

            var brandVms = GetCollectionResponse <BrandVm>(result);

            Assert.NotNull(brandVms);
            foreach (var brand in brands)
            {
                Assert.Contains(brandVms, x => x.Name == brand.Name);
            }
        }
Exemplo n.º 2
0
        public async Task BrandsController_Put_Success()
        {
            var createRequest = new BrandCreateRequest {
                Name = "Test brand5"
            };

            var controller   = new BrandsController(_fixture.BrandService);
            var createResult = await controller.Post(createRequest);

            var createResponse = GetResponse <BrandCreateResponse>(createResult);

            Assert.Equal(createRequest.Name, createResponse.Name);

            var updateRequest = new BrandUpdateRequest
            {
                Id   = createResponse.Id,
                Name = "New Name"
            };
            var updateResult = await controller.Put(updateRequest);

            var updateResponse = GetResponse <BrandUpdateResponse>(updateResult);

            Assert.Equal(updateRequest.Id, updateResponse.Id);
            Assert.Equal(updateRequest.Name, updateResponse.Name);
        }
Exemplo n.º 3
0
        public async Task BrandsController_Post_Success()
        {
            var brand = new BrandCreateRequest {
                Name = "Test brand4"
            };

            var controller = new BrandsController(_fixture.BrandService);
            var result     = await controller.Post(brand);

            var response = GetResponse <BrandCreateResponse>(result);

            Assert.Equal(brand.Name, response.Name);
        }
        public void Post_ShouldReturnId()
        {
            //Arrange
            var testBrand  = BrandBuilderBuilder.GetTestBrand();
            var mock       = new Mock <IBrandService>();
            var controller = new BrandsController(mock.Object);

            //Act
            mock.Setup(p => p.Post <BrandValidator>(testBrand)).Returns(testBrand);
            var result = controller.Post(testBrand) as OkObjectResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(200, result.StatusCode);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(1, result.Value);
        }
Exemplo n.º 5
0
        public async Task BrandsController_Get_Success()
        {
            var brand = new BrandCreateRequest {
                Name = "Test brand3"
            };

            var controller   = new BrandsController(_fixture.BrandService);
            var createResult = await controller.Post(brand);

            var createResponse = GetResponse <BrandCreateResponse>(createResult);

            Assert.Equal(brand.Name, createResponse.Name);

            var getResult = await controller.Get(createResponse.Id);

            var brandVm = GetResponse <BrandVm>(getResult);

            Assert.Equal(createResponse.Id, brandVm.Id);
            Assert.Equal(brand.Name, brandVm.Name);
        }
Exemplo n.º 6
0
        public async Task BrandsController_Delete_Success()
        {
            var createRequest = new BrandCreateRequest {
                Name = "Test brand6"
            };

            var controller   = new BrandsController(_fixture.BrandService);
            var createResult = await controller.Post(createRequest);

            var createResponse = GetResponse <BrandCreateResponse>(createResult);

            Assert.Equal("Test brand6", createResponse.Name);

            var deleteResult = await controller.Delete(createResponse.Id);

            Assert.IsType <OkResult>(deleteResult);

            var getResult = await controller.Get(createResponse.Id);

            var getOkResult = Assert.IsType <OkObjectResult>(getResult);

            Assert.Null(getOkResult.Value);
        }
Exemplo n.º 7
0
        public async void AddBrand_ReturnBrandCreated()
        {
            // Arrange
            var mockRepo = new Mock <IVehicleCatalogRepository>();

            mockRepo.Setup(repo => repo.SaveAll())
            .Returns(Task.FromResult <bool>(true));
            var         mapper     = _dependencyFixture.ServiceProvider.GetService <IMapper>();
            var         logger     = Mock.Of <ILogger <BrandsController> >();
            var         controller = new BrandsController(mockRepo.Object, mapper, logger);
            BrandForNew newBrand   = new BrandForNew()
            {
                name = "Fake"
            };

            // Act
            var result = await controller.Post(newBrand);

            // Assert
            var okResult    = Assert.IsType <CreatedAtRouteResult>(result);
            var returnValue = Assert.IsType <string>(okResult.Value);

            Assert.Equal("Brand created.", returnValue);
        }
Exemplo n.º 8
0
        public void Post_ReturnsNoContentType_WhenBrandExists()
        {
            var result = brandController.Post(brandDto);

            Assert.IsInstanceOf(typeof(NoContentResult), result);
        }