Ejemplo n.º 1
0
        public virtual async void TestByDeviceIdFound()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            List <ApiDeviceActionClientResponseModel> response = await client.ByDeviceActionByDeviceId(1);

            response.Should().NotBeEmpty();
            response[0].Action.Should().Be("A");
            response[0].DeviceId.Should().Be(1);
            response[0].Id.Should().Be(1);
            response[0].Name.Should().Be("A");
        }
Ejemplo n.º 2
0
        public virtual async void TestAll()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            List <ApiDeviceClientResponseModel> response = await client.DeviceAllAsync();

            response.Count.Should().BeGreaterThan(0);
            response[0].DateOfLastPing.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response[0].Id.Should().Be(1);
            response[0].IsActive.Should().Be(true);
            response[0].Name.Should().Be("A");
            response[0].PublicId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Ejemplo n.º 3
0
        public virtual async void TestGetFound()
        {
            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;

            ApiDeviceActionClientResponseModel response = await client.DeviceActionGetAsync(1);

            response.Should().NotBeNull();
            response.Action.Should().Be("A");
            response.DeviceId.Should().Be(1);
            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
        }
Ejemplo n.º 4
0
        public virtual async void TestGetFound()
        {
            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;

            ApiDeviceClientResponseModel response = await client.DeviceGetAsync(1);

            response.Should().NotBeNull();
            response.DateOfLastPing.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Id.Should().Be(1);
            response.IsActive.Should().Be(true);
            response.Name.Should().Be("A");
            response.PublicId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Ejemplo n.º 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 ApiDeviceClientRequestModel();

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

            model2.SetProperties(DateTime.Parse("1/1/1989 12:00:00 AM"), true, "C", Guid.Parse("8d721ec8-4c9d-632f-6f06-7f89cc14862c"));
            var request = new List <ApiDeviceClientRequestModel>()
            {
                model, model2
            };
            CreateResponse <List <ApiDeviceClientResponseModel> > result = await client.DeviceBulkInsertAsync(request);

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

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

            context.Set <Device>().ToList()[2].DateOfLastPing.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM"));
            context.Set <Device>().ToList()[2].IsActive.Should().Be(true);
            context.Set <Device>().ToList()[2].Name.Should().Be("C");
            context.Set <Device>().ToList()[2].PublicId.Should().Be(Guid.Parse("8d721ec8-4c9d-632f-6f06-7f89cc14862c"));
        }
Ejemplo n.º 6
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"));
        }