Пример #1
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiTeacherServerModelMapper();
            var model  = new ApiTeacherServerResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1);
            ApiTeacherServerRequestModel response = mapper.MapServerResponseToRequest(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);
        }
Пример #2
0
        public void CreatePatch()
        {
            var mapper = new ApiTeacherServerModelMapper();
            var model  = new ApiTeacherServerRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1);

            JsonPatchDocument <ApiTeacherServerRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiTeacherServerRequestModel();

            patch.ApplyTo(response);
            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);
        }
Пример #3
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());

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

            ApiTeacherClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiTeacherClientResponseModel> updateResponse = await client.TeacherUpdateAsync(model.Id, request);

            context.Entry(context.Set <Teacher>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Teacher>().ToList()[0].Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Teacher>().ToList()[0].Email.Should().Be("B");
            context.Set <Teacher>().ToList()[0].FirstName.Should().Be("B");
            context.Set <Teacher>().ToList()[0].LastName.Should().Be("B");
            context.Set <Teacher>().ToList()[0].Phone.Should().Be("B");
            context.Set <Teacher>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.Email.Should().Be("B");
            updateResponse.Record.FirstName.Should().Be("B");
            updateResponse.Record.LastName.Should().Be("B");
            updateResponse.Record.Phone.Should().Be("B");
            updateResponse.Record.UserId.Should().Be(1);
        }