public void DeleteTest() { Device v = new Device(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = "44tvMxOP9"; v.ProductId = AddProduct(); context.Set <Device>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(DeviceVM)); DeviceVM vm = rv.Model as DeviceVM; v = new Device(); v.ID = vm.Entity.ID; vm.Entity = v; _controller.Delete(v.ID.ToString(), null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <Device>().Count(), 0); } }
public void DeleteDevice_Success() { //Arrange _deviceController.ControllerContext.Request.Properties["UserDetails"] = GetValidUserDomain(); // Act IHttpActionResult actionResult = _deviceController.Delete(1); var contentResult = actionResult as OkNegotiatedContentResult <bool>; // Assert Assert.IsNotNull(contentResult); Assert.IsTrue(contentResult.Content); }
public async void Delete_Errors() { DeviceControllerMockFacade mock = new DeviceControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); DeviceController controller = new DeviceController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public async Task Delete_WithDeviceId_ReturnsOkResult() { // Arrange var dbContext = Setup.GetDbContext(); var deviceEntry = dbContext.Devices.Add(new Device() { Id = 10, Name = "DeviceName", NormalizedName = "DEVICENAME" }); await dbContext.SaveChangesAsync(); deviceEntry.State = EntityState.Detached; var controller = new DeviceController(dbContext); // Act var result = await controller.Delete(10); // Assert Assert.IsType <OkResult>(result); Assert.Empty(dbContext.Devices); }