Esempio n. 1
0
        public virtual async void TestBulkInsert()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer           testServer = new TestServer(builder);
            var                  client     = new ApiClient(testServer.CreateClient());
            ApplicationDbContext context    = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            var model = new ApiEmailClientRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1988 12:00:00 AM"), "B");
            var model2 = new ApiEmailClientRequestModel();

            model2.SetProperties(1, DateTime.Parse("1/1/1989 12:00:00 AM"), "C");
            var request = new List <ApiEmailClientRequestModel>()
            {
                model, model2
            };
            CreateResponse <List <ApiEmailClientResponseModel> > result = await client.EmailBulkInsertAsync(request);

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

            context.Set <Email>().ToList()[1].ArtistId.Should().Be(1);
            context.Set <Email>().ToList()[1].DateCreated.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Email>().ToList()[1].EmailValue.Should().Be("B");

            context.Set <Email>().ToList()[2].ArtistId.Should().Be(1);
            context.Set <Email>().ToList()[2].DateCreated.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM"));
            context.Set <Email>().ToList()[2].EmailValue.Should().Be("C");
        }
Esempio n. 2
0
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            var mapper = new ApiEmailServerModelMapper();
            ApplicationDbContext        context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IEmailService               service = testServer.Host.Services.GetService(typeof(IEmailService)) as IEmailService;
            ApiEmailServerResponseModel model   = await service.Get(1);

            ApiEmailClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(1, DateTime.Parse("1/1/1988 12:00:00 AM"), "B");

            UpdateResponse <ApiEmailClientResponseModel> updateResponse = await client.EmailUpdateAsync(model.Id, request);

            context.Entry(context.Set <Email>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Email>().ToList()[0].ArtistId.Should().Be(1);
            context.Set <Email>().ToList()[0].DateCreated.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Email>().ToList()[0].EmailValue.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.ArtistId.Should().Be(1);
            updateResponse.Record.DateCreated.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.EmailValue.Should().Be("B");
        }
        public virtual ApiEmailClientRequestModel MapServerResponseToClientRequest(
            ApiEmailServerResponseModel response)
        {
            var request = new ApiEmailClientRequestModel();

            request.SetProperties(
                response.ArtistId,
                response.DateCreated,
                response.EmailValue);
            return(request);
        }
Esempio n. 4
0
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiEmailModelMapper();
            var model  = new ApiEmailClientRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            ApiEmailClientResponseModel response = mapper.MapClientRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.ArtistId.Should().Be(1);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.EmailValue.Should().Be("A");
        }