Beispiel #1
0
        public async Task Should_Add_And_Remove_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 deleteResult = await controller.RemoveDevice(foundItem.DeviceId.ToString());

            var foundItem2 = await controller.GetDevice((added.Value as Device).DeviceId.ToString()) as NotFoundObjectResult;

            Assert.Equal(foundItem2.StatusCode, (int)HttpStatusCode.NotFound);
        }