public async Task ShouldReturnBadRequestWhenDeviceIsNotSet()
        {
            IDeviceRepository deviceRepository = Mock.Of<IDeviceRepository>();
            IMeasurementUnitRepository measurementUnitRepository = Mock.Of<IMeasurementUnitRepository>();
            DeviceController controller = new DeviceController(deviceRepository, measurementUnitRepository);

            controller.WithCallTo(c => c.Create(null))
                      .ShouldRenderDefaultView();
        }
        public async Task ShouldReturnConflictWhenDeviceWithSameNameAlreadyExist()
        {
            string deviceName = "Raspberry Pi";
            Device device = new Device { Name = deviceName };

            var mock = new Mock<IDeviceRepository>();
            mock.Setup(m => m.GetDeviceByNameAsync(deviceName))
                .ReturnsAsync(device);

            IDeviceRepository deviceRepository = mock.Object;
            IMeasurementUnitRepository measurementUnitRepository = Mock.Of<IMeasurementUnitRepository>();
            DeviceController controller = new DeviceController(deviceRepository, measurementUnitRepository);

            controller.WithCallTo(c => c.Create(device))
                      .ShouldRenderDefaultView()
                      .WithModel(device);
        }
        public async Task ShouldRedirectWhenDeviceIsCreated()
        {
            Device device = new Device { Name = "Raspberry Pi" };
            var mock = new Mock<IDeviceRepository>();
            mock.Setup(m => m.GetDeviceByNameAsync(device.Name))
                .ReturnsAsync(null);

            var context = new Mock<HttpContextBase>();
            var identity = new GenericIdentity("*****@*****.**");
            identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "1"));
            var principal = new GenericPrincipal(identity, new[] { "user" });
            context.Setup(s => s.User).Returns(principal);

            IDeviceRepository deviceRepository = mock.Object;
            IMeasurementUnitRepository measurementUnitRepository = Mock.Of<IMeasurementUnitRepository>();
            DeviceController controller = new DeviceController(deviceRepository, measurementUnitRepository);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            controller.WithCallTo(c => c.Create(device))
                      .ShouldRedirectTo(c => c.Details(1));
        }