public void MapServerResponseToRequest()
        {
            var mapper = new ApiNoteServerModelMapper();
            var model  = new ApiNoteServerResponseModel();

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

            response.Should().NotBeNull();
            response.CallId.Should().Be(1);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.NoteText.Should().Be("A");
            response.OfficerId.Should().Be(1);
        }
        public void CreatePatch()
        {
            var mapper = new ApiNoteServerModelMapper();
            var model  = new ApiNoteServerRequestModel();

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

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

            patch.ApplyTo(response);
            response.CallId.Should().Be(1);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.NoteText.Should().Be("A");
            response.OfficerId.Should().Be(1);
        }
Beispiel #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 ApiNoteServerModelMapper();
            ApplicationDbContext       context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            INoteService               service = testServer.Host.Services.GetService(typeof(INoteService)) as INoteService;
            ApiNoteServerResponseModel model   = await service.Get(1);

            ApiNoteClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiNoteClientResponseModel> updateResponse = await client.NoteUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CallId.Should().Be(1);
            updateResponse.Record.DateCreated.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.NoteText.Should().Be("B");
            updateResponse.Record.OfficerId.Should().Be(1);
        }