public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IProductService service = testServer.Host.Services.GetService(typeof(IProductService)) as IProductService;
            var             model   = new ApiProductServerRequestModel();

            model.SetProperties(true, "B", "B", 2m, 2);
            CreateResponse <ApiProductServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.ProductDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiProductServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Esempio n. 2
0
        public void MapServerRequestToResponse()
        {
            var mapper = new ApiProductServerModelMapper();
            var model  = new ApiProductServerRequestModel();

            model.SetProperties(true, "A", "A", 1m, 1);
            ApiProductServerResponseModel response = mapper.MapServerRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.Active.Should().Be(true);
            response.Description.Should().Be("A");
            response.Name.Should().Be("A");
            response.Price.Should().Be(1m);
            response.Quantity.Should().Be(1);
        }
Esempio n. 3
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IProductService, IProductRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Product>(null));
            var service = new ProductService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.ProductModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALProductMapperMock);

            ApiProductServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }