Пример #1
0
        public async Task Should_Add_And_Update_A_Device()
        {
            var consumerController = new ConsumersController(fixture.GetDataProvider());
            var consumer           = (await consumerController.AddConsumer(new ConsumerRequestAdd()
            {
                Email = "*****@*****.**"
            }) as OkObjectResult).Value as Consumer;

            var device = new DeviceRequestAdd()
            {
                Available    = true,
                Description  = "Description...",
                ProjectId    = "Project test",
                Regionid     = "europe-west1",
                RegisteredOn = System.DateTime.Now,
                RegistryId   = "my-registry",
                TenantId     = Guid.NewGuid().ToString(),
                ConsumerId   = consumer.ConsumerId.ToString()
            };
            //-------------------------------------------

            var controller = new DevicesController(fixture.GetDataProvider());
            var added      = await controller.AddDevice(device) as OkObjectResult;

            Assert.NotNull(added.Value);
            Assert.Equal(added.StatusCode, (int)HttpStatusCode.OK);

            var foundItem = (await controller.GetDevice((added.Value as Device).DeviceId.ToString()) as OkObjectResult).Value as Device;

            Assert.Equal(foundItem, added.Value);

            var deviceUpdate = new DeviceRequestUpdate()
            {
                DeviceId     = foundItem.DeviceId.ToString(),
                Available    = false,
                Description  = "Updated description...",
                ProjectId    = "Updated project test",
                Regionid     = "europe-west2",
                RegisteredOn = DateTime.Now,
                RegistryId   = "my-registry updated",
                TenantId     = Guid.NewGuid().ToString(),
                ConsumerId   = consumer.ConsumerId.ToString()
            };

            var updated = await controller.UpdateDevice(deviceUpdate.DeviceId, deviceUpdate) as OkObjectResult;

            var updatedItem = (await controller.GetDevice((updated.Value as Device).DeviceId.ToString()) as OkObjectResult).Value as Device;

            Assert.False(updatedItem.Available);
            Assert.Equal("Updated description...", updatedItem.Description);
            Assert.Equal("Updated project test", updatedItem.ProjectId);
            Assert.Equal("europe-west2", updatedItem.Regionid);
            Assert.Equal("my-registry updated", updatedItem.RegistryId);
        }