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 ApiAdminClientRequestModel();

            model.SetProperties("B", "B", "B", "B", "B", "B");
            CreateResponse <ApiAdminClientResponseModel> result = await client.AdminCreateAsync(model);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Admin>().ToList()[1].Email.Should().Be("B");
            context.Set <Admin>().ToList()[1].FirstName.Should().Be("B");
            context.Set <Admin>().ToList()[1].LastName.Should().Be("B");
            context.Set <Admin>().ToList()[1].Password.Should().Be("B");
            context.Set <Admin>().ToList()[1].Phone.Should().Be("B");
            context.Set <Admin>().ToList()[1].Username.Should().Be("B");

            result.Record.Email.Should().Be("B");
            result.Record.FirstName.Should().Be("B");
            result.Record.LastName.Should().Be("B");
            result.Record.Password.Should().Be("B");
            result.Record.Phone.Should().Be("B");
            result.Record.Username.Should().Be("B");
        }
Beispiel #2
0
        public virtual ApiAdminClientRequestModel MapServerResponseToClientRequest(
            ApiAdminServerResponseModel response)
        {
            var request = new ApiAdminClientRequestModel();

            request.SetProperties(
                response.Email,
                response.FirstName,
                response.LastName,
                response.Password,
                response.Phone,
                response.Username);
            return(request);
        }
Beispiel #3
0
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiAdminModelMapper();
            var model  = new ApiAdminClientRequestModel();

            model.SetProperties("A", "A", "A", "A", "A", "A");
            ApiAdminClientResponseModel response = mapper.MapClientRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Password.Should().Be("A");
            response.Phone.Should().Be("A");
            response.Username.Should().Be("A");
        }
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiAdminModelMapper();
            var model  = new ApiAdminClientRequestModel();

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

            response.Should().NotBeNull();
            response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
            response.UserId.Should().Be(1);
        }
Beispiel #5
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());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());

            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            var model = new ApiAdminClientRequestModel();

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

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

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

            context.Set <Admin>().ToList()[1].Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Admin>().ToList()[1].Email.Should().Be("B");
            context.Set <Admin>().ToList()[1].FirstName.Should().Be("B");
            context.Set <Admin>().ToList()[1].LastName.Should().Be("B");
            context.Set <Admin>().ToList()[1].Phone.Should().Be("B");
            context.Set <Admin>().ToList()[1].UserId.Should().Be(1);

            context.Set <Admin>().ToList()[2].Birthday.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM"));
            context.Set <Admin>().ToList()[2].Email.Should().Be("C");
            context.Set <Admin>().ToList()[2].FirstName.Should().Be("C");
            context.Set <Admin>().ToList()[2].LastName.Should().Be("C");
            context.Set <Admin>().ToList()[2].Phone.Should().Be("C");
            context.Set <Admin>().ToList()[2].UserId.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 ApiAdminServerModelMapper();
            ApplicationDbContext        context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IAdminService               service = testServer.Host.Services.GetService(typeof(IAdminService)) as IAdminService;
            ApiAdminServerResponseModel model   = await service.Get(1);

            ApiAdminClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiAdminClientResponseModel> updateResponse = await client.AdminUpdateAsync(model.Id, request);

            context.Entry(context.Set <Admin>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Admin>().ToList()[0].Email.Should().Be("B");
            context.Set <Admin>().ToList()[0].FirstName.Should().Be("B");
            context.Set <Admin>().ToList()[0].LastName.Should().Be("B");
            context.Set <Admin>().ToList()[0].Password.Should().Be("B");
            context.Set <Admin>().ToList()[0].Phone.Should().Be("B");
            context.Set <Admin>().ToList()[0].Username.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.Password.Should().Be("B");
            updateResponse.Record.Phone.Should().Be("B");
            updateResponse.Record.Username.Should().Be("B");
        }