示例#1
0
        public virtual async void TestByCustomerIdFound()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            List <ApiSaleClientResponseModel> response = await client.BySaleByCustomerId(1);

            response.Should().NotBeEmpty();
            response[0].CustomerId.Should().Be(1);
            response[0].Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response[0].Id.Should().Be(1);
        }
        public virtual async void TestAll()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            List <ApiCustomerClientResponseModel> response = await client.CustomerAllAsync();

            response.Count.Should().BeGreaterThan(0);
            response[0].Email.Should().Be("A");
            response[0].FirstName.Should().Be("A");
            response[0].Id.Should().Be(1);
            response[0].LastName.Should().Be("A");
            response[0].Phone.Should().Be("A");
        }
示例#3
0
        public virtual async void TestGetFound()
        {
            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;

            ApiSaleClientResponseModel response = await client.SaleGetAsync(1);

            response.Should().NotBeNull();
            response.CustomerId.Should().Be(1);
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Id.Should().Be(1);
        }
        public virtual async void TestAll()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            List <ApiProductClientResponseModel> response = await client.ProductAllAsync();

            response.Count.Should().BeGreaterThan(0);
            response[0].Active.Should().Be(true);
            response[0].Description.Should().Be("A");
            response[0].Id.Should().Be(1);
            response[0].Name.Should().Be("A");
            response[0].Price.Should().Be(1m);
            response[0].Quantity.Should().Be(1);
        }
        public virtual async void TestGetFound()
        {
            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;

            ApiCustomerClientResponseModel response = await client.CustomerGetAsync(1);

            response.Should().NotBeNull();
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.Id.Should().Be(1);
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
        public virtual async void TestBulkInsert()
        {
            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;

            var model = new ApiProductClientRequestModel();

            model.SetProperties(true, "B", "B", 2m, 2);
            var model2 = new ApiProductClientRequestModel();

            model2.SetProperties(true, "C", "C", 3m, 3);
            var request = new List <ApiProductClientRequestModel>()
            {
                model, model2
            };
            CreateResponse <List <ApiProductClientResponseModel> > result = await client.ProductBulkInsertAsync(request);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();

            context.Set <Product>().ToList()[1].Active.Should().Be(true);
            context.Set <Product>().ToList()[1].Description.Should().Be("B");
            context.Set <Product>().ToList()[1].Name.Should().Be("B");
            context.Set <Product>().ToList()[1].Price.Should().Be(2m);
            context.Set <Product>().ToList()[1].Quantity.Should().Be(2);

            context.Set <Product>().ToList()[2].Active.Should().Be(true);
            context.Set <Product>().ToList()[2].Description.Should().Be("C");
            context.Set <Product>().ToList()[2].Name.Should().Be("C");
            context.Set <Product>().ToList()[2].Price.Should().Be(3m);
            context.Set <Product>().ToList()[2].Quantity.Should().Be(3);
        }
        public virtual async void TestGetFound()
        {
            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;

            ApiProductClientResponseModel response = await client.ProductGetAsync(1);

            response.Should().NotBeNull();
            response.Active.Should().Be(true);
            response.Description.Should().Be("A");
            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
            response.Price.Should().Be(1m);
            response.Quantity.Should().Be(1);
        }
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiProductServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IProductService               service = testServer.Host.Services.GetService(typeof(IProductService)) as IProductService;
            ApiProductServerResponseModel model   = await service.Get(1);

            ApiProductClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(true, "B", "B", 2m, 2);

            UpdateResponse <ApiProductClientResponseModel> updateResponse = await client.ProductUpdateAsync(model.Id, request);

            context.Entry(context.Set <Product>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Product>().ToList()[0].Active.Should().Be(true);
            context.Set <Product>().ToList()[0].Description.Should().Be("B");
            context.Set <Product>().ToList()[0].Name.Should().Be("B");
            context.Set <Product>().ToList()[0].Price.Should().Be(2m);
            context.Set <Product>().ToList()[0].Quantity.Should().Be(2);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Active.Should().Be(true);
            updateResponse.Record.Description.Should().Be("B");
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.Price.Should().Be(2m);
            updateResponse.Record.Quantity.Should().Be(2);
        }
        public virtual async void TestBulkInsert()
        {
            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;

            var model = new ApiCustomerClientRequestModel();

            model.SetProperties("B", "B", "B", "B");
            var model2 = new ApiCustomerClientRequestModel();

            model2.SetProperties("C", "C", "C", "C");
            var request = new List <ApiCustomerClientRequestModel>()
            {
                model, model2
            };
            CreateResponse <List <ApiCustomerClientResponseModel> > result = await client.CustomerBulkInsertAsync(request);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();

            context.Set <Customer>().ToList()[1].Email.Should().Be("B");
            context.Set <Customer>().ToList()[1].FirstName.Should().Be("B");
            context.Set <Customer>().ToList()[1].LastName.Should().Be("B");
            context.Set <Customer>().ToList()[1].Phone.Should().Be("B");

            context.Set <Customer>().ToList()[2].Email.Should().Be("C");
            context.Set <Customer>().ToList()[2].FirstName.Should().Be("C");
            context.Set <Customer>().ToList()[2].LastName.Should().Be("C");
            context.Set <Customer>().ToList()[2].Phone.Should().Be("C");
        }
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiCustomerServerModelMapper();
            ApplicationDbContext           context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ICustomerService               service = testServer.Host.Services.GetService(typeof(ICustomerService)) as ICustomerService;
            ApiCustomerServerResponseModel model   = await service.Get(1);

            ApiCustomerClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", "B", "B", "B");

            UpdateResponse <ApiCustomerClientResponseModel> updateResponse = await client.CustomerUpdateAsync(model.Id, request);

            context.Entry(context.Set <Customer>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Customer>().ToList()[0].Email.Should().Be("B");
            context.Set <Customer>().ToList()[0].FirstName.Should().Be("B");
            context.Set <Customer>().ToList()[0].LastName.Should().Be("B");
            context.Set <Customer>().ToList()[0].Phone.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Email.Should().Be("B");
            updateResponse.Record.FirstName.Should().Be("B");
            updateResponse.Record.LastName.Should().Be("B");
            updateResponse.Record.Phone.Should().Be("B");
        }
示例#11
0
        public virtual async void TestCreate()
        {
            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;

            var model = new ApiSaleClientRequestModel();

            model.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"));
            CreateResponse <ApiSaleClientResponseModel> result = await client.SaleCreateAsync(model);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Sale>().ToList()[1].CustomerId.Should().Be(2);
            context.Set <Sale>().ToList()[1].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));

            result.Record.CustomerId.Should().Be(2);
            result.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
        }