コード例 #1
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiMessengerServerModelMapper();
            var model  = new ApiMessengerServerResponseModel();

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

            response.Should().NotBeNull();
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FromUserId.Should().Be(1);
            response.MessageId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
            response.ToUserId.Should().Be(1);
            response.UserId.Should().Be(1);
        }
コード例 #2
0
        public void CreatePatch()
        {
            var mapper = new ApiMessengerServerModelMapper();
            var model  = new ApiMessengerServerRequestModel();

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

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

            patch.ApplyTo(response);
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FromUserId.Should().Be(1);
            response.MessageId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
            response.ToUserId.Should().Be(1);
            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 ApiMessengerServerModelMapper();
            ApplicationDbContext            context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IMessengerService               service = testServer.Host.Services.GetService(typeof(IMessengerService)) as IMessengerService;
            ApiMessengerServerResponseModel model   = await service.Get(1);

            ApiMessengerClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiMessengerClientResponseModel> updateResponse = await client.MessengerUpdateAsync(model.Id, request);

            context.Entry(context.Set <Messenger>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Messenger>().ToList()[0].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Messenger>().ToList()[0].FromUserId.Should().Be(2);
            context.Set <Messenger>().ToList()[0].MessageId.Should().Be(1);
            context.Set <Messenger>().ToList()[0].Time.Should().Be(TimeSpan.Parse("02:00:00"));
            context.Set <Messenger>().ToList()[0].ToUserId.Should().Be(1);
            context.Set <Messenger>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.FromUserId.Should().Be(2);
            updateResponse.Record.MessageId.Should().Be(1);
            updateResponse.Record.Time.Should().Be(TimeSpan.Parse("02:00:00"));
            updateResponse.Record.ToUserId.Should().Be(1);
            updateResponse.Record.UserId.Should().Be(1);
        }