Esempio n. 1
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiDeviceServerModelMapper();
            var model  = new ApiDeviceServerResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            ApiDeviceServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.DateOfLastPing.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.IsActive.Should().Be(true);
            response.Name.Should().Be("A");
            response.PublicId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Esempio n. 2
0
        public void CreatePatch()
        {
            var mapper = new ApiDeviceServerModelMapper();
            var model  = new ApiDeviceServerRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));

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

            patch.ApplyTo(response);
            response.DateOfLastPing.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.IsActive.Should().Be(true);
            response.Name.Should().Be("A");
            response.PublicId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Esempio n. 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 ApiDeviceServerModelMapper();
            ApplicationDbContext         context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IDeviceService               service = testServer.Host.Services.GetService(typeof(IDeviceService)) as IDeviceService;
            ApiDeviceServerResponseModel model   = await service.Get(1);

            ApiDeviceClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), true, "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"));

            UpdateResponse <ApiDeviceClientResponseModel> updateResponse = await client.DeviceUpdateAsync(model.Id, request);

            context.Entry(context.Set <Device>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Device>().ToList()[0].DateOfLastPing.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Device>().ToList()[0].IsActive.Should().Be(true);
            context.Set <Device>().ToList()[0].Name.Should().Be("B");
            context.Set <Device>().ToList()[0].PublicId.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"));

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.DateOfLastPing.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.IsActive.Should().Be(true);
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.PublicId.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"));
        }