public void TestDeleteWorkgroupVendorWhenFound1() { #region Arrange new FakeWorkgroups(4, WorkgroupRepository); var workgroupVendors = new List <WorkgroupVendor>(); for (int i = 0; i < 3; i++) { workgroupVendors.Add(CreateValidEntities.WorkgroupVendor(i + 1)); workgroupVendors[i].IsActive = true; workgroupVendors[i].Workgroup = WorkgroupRepository.GetNullableById(i + 2); } workgroupVendors[2].IsActive = false; new FakeWorkgroupVendors(3, WorkgroupVendorRepository, workgroupVendors); #endregion Arrange #region Act var result = Controller.DeleteWorkgroupVendor(3, 2, null) .AssertActionRedirect() .ToAction <WorkgroupController>(a => a.VendorList(3)); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(3, result.RouteValues["id"]); Assert.AreEqual("WorkgroupVendor Removed Successfully", Controller.Message); WorkgroupVendorRepository.AssertWasNotCalled(a => a.Remove(Arg <WorkgroupVendor> .Is.Anything)); WorkgroupVendorRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); var args = (WorkgroupVendor)WorkgroupVendorRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything))[0][0]; Assert.IsNotNull(args); Assert.AreEqual(2, args.Id); Assert.IsFalse(args.IsActive); #endregion Assert }
public void TestCreateVendorPostWithInvalidValueReturnsView4() { #region Arrange SetupDataForVendors3(); var vendorToCreate = CreateValidEntities.WorkgroupVendor(9); vendorToCreate.VendorId = null; vendorToCreate.City = null; WorkgroupService.Expect(a => a.TransferValues(Arg <WorkgroupVendor> .Is.Anything, ref Arg <WorkgroupVendor> .Ref(Is.Anything(), vendorToCreate).Dummy)); #endregion Arrange #region Act var result = Controller.CreateVendor(3, vendorToCreate, true) .AssertViewRendered() .WithViewData <WorkgroupVendorViewModel>(); #endregion Act #region Assert WorkgroupVendorRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); Controller.ModelState.AssertErrorsAre("The City field is required."); Assert.IsNotNull(result); Assert.AreEqual(true, result.NewVendor); Assert.AreEqual(null, result.VendorAddress); Assert.AreEqual(null, result.WorkgroupVendor.City); Assert.AreEqual("Line19", result.WorkgroupVendor.Line1); Assert.AreEqual(null, result.Vendor); #endregion Assert }
public void TestCreateVendorPostWhenValidRedirectsAndSaves4() { #region Arrange SetupDataForVendors2(); var vendorToCreate = CreateValidEntities.WorkgroupVendor(9); vendorToCreate.VendorId = null; WorkgroupService.Expect(a => a.TransferValues(Arg <WorkgroupVendor> .Is.Anything, ref Arg <WorkgroupVendor> .Ref(Is.Anything(), vendorToCreate).Dummy)); #endregion Arrange #region Act var result = Controller.CreateVendor(3, vendorToCreate, true) .AssertActionRedirect() .ToAction <WorkgroupController>(a => a.VendorList(3)); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(3, result.RouteValues["id"]); Assert.AreEqual("WorkgroupVendor Created Successfully", Controller.Message); WorkgroupVendorRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); var args = (WorkgroupVendor)WorkgroupVendorRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything))[0][0]; Assert.IsNotNull(args); Assert.AreEqual(null, args.VendorId); Assert.AreEqual("tc9", args.VendorAddressTypeCode); Assert.AreEqual("Name9", args.Name); #endregion Assert }
public void TestEditWorkgroupVendorPostRedirectsWhenValid() { #region Arrange new FakeVendors(3, VendorRepository); var workgroup = CreateValidEntities.Workgroup(15); workgroup.SetIdTo(15); var workgroupVendors = new List <WorkgroupVendor>(); workgroupVendors.Add(CreateValidEntities.WorkgroupVendor(5)); workgroupVendors[0].VendorId = null; workgroupVendors[0].VendorAddressTypeCode = null; workgroupVendors[0].Workgroup = workgroup; new FakeWorkgroupVendors(0, WorkgroupVendorRepository, workgroupVendors); var workgroupVendor = CreateValidEntities.WorkgroupVendor(9); workgroupVendor.Workgroup.SetIdTo(15); workgroupVendor.VendorId = null; workgroupVendor.VendorAddressTypeCode = null; workgroupVendor.Name = "Changed"; WorkgroupService.Expect(a => a.TransferValues(Arg <WorkgroupVendor> .Is.Anything, ref Arg <WorkgroupVendor> .Ref(Is.Anything(), workgroupVendor).Dummy)); #endregion Arrange #region Act var result = Controller.EditWorkgroupVendor(15, 1, workgroupVendor) .AssertActionRedirect() .ToAction <WorkgroupController>(a => a.VendorList(15)); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(15, result.RouteValues["id"]); Assert.AreEqual("WorkgroupVendor Edited Successfully", Controller.Message); WorkgroupVendorRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything), x => x.Repeat.Times(2)); var oldArgs = (WorkgroupVendor)WorkgroupVendorRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything))[0][0]; var newArgs = (WorkgroupVendor)WorkgroupVendorRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything))[1][0]; Assert.IsNotNull(oldArgs); Assert.AreEqual("Name5", oldArgs.Name); Assert.IsFalse(oldArgs.IsActive); Assert.IsNotNull(newArgs); Assert.AreEqual("Changed", newArgs.Name); Assert.IsTrue(newArgs.IsActive); #endregion Assert }
public void TestEditWorkgroupVendorPostRedirectsWhenNotFound() { #region Arrange new FakeWorkgroupVendors(3, WorkgroupVendorRepository); #endregion Arrange #region Act Controller.EditWorkgroupVendor(0, 4, new WorkgroupVendor()) .AssertActionRedirect() .ToAction <WorkgroupController>(a => a.Index(false)); #endregion Act #region Assert Assert.AreEqual("Workgroup Vendor not found.", Controller.ErrorMessage); WorkgroupVendorRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); #endregion Assert }
public void TestDeleteWorkgroupVendorGetRedirectsToIndesWhenNotFound() { #region Arrange new FakeWorkgroupVendors(3, WorkgroupVendorRepository); #endregion Arrange #region Act Controller.DeleteWorkgroupVendor(0, 4) .AssertActionRedirect() .ToAction <WorkgroupController>(a => a.Index(false)); #endregion Act #region Assert WorkgroupVendorRepository.AssertWasNotCalled(a => a.Remove(Arg <WorkgroupVendor> .Is.Anything)); WorkgroupVendorRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); #endregion Assert }
public void TestDeleteWorkgroupVendorGetReturnView() { #region Arrange new FakeWorkgroupVendors(3, WorkgroupVendorRepository); #endregion Arrange #region Act var result = Controller.DeleteWorkgroupVendor(0, 3) .AssertViewRendered() .WithViewData <WorkgroupVendor>(); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(3, result.Id); WorkgroupVendorRepository.AssertWasNotCalled(a => a.Remove(Arg <WorkgroupVendor> .Is.Anything)); WorkgroupVendorRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); #endregion Assert }
public void TestCreateVendorPostWithInvalidValueReturnsView1() { #region Arrange SetupDataForVendors3(); var vendorToCreate = CreateValidEntities.WorkgroupVendor(9); vendorToCreate.Line1 = null; WorkgroupService.Expect(a => a.TransferValues(Arg <WorkgroupVendor> .Is.Anything, ref Arg <WorkgroupVendor> .Ref(Is.Anything(), vendorToCreate).Dummy)); #endregion Arrange #region Act Controller.CreateVendor(3, vendorToCreate, false) .AssertViewRendered() .WithViewData <WorkgroupVendorViewModel>(); #endregion Act #region Assert WorkgroupVendorRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); Controller.ModelState.AssertErrorsAre("The Line1 field is required."); #endregion Assert }
public void TestEditWorkgroupVendorPostWhereKfsRedirects() { #region Arrange var workgroupVendors = new List <WorkgroupVendor>(); workgroupVendors.Add(CreateValidEntities.WorkgroupVendor(1)); workgroupVendors[0].Workgroup = CreateValidEntities.Workgroup(9); workgroupVendors[0].Workgroup.SetIdTo(15); new FakeWorkgroupVendors(0, WorkgroupVendorRepository, workgroupVendors); #endregion Arrange #region Act var result = Controller.EditWorkgroupVendor(15, 1, new WorkgroupVendor()) .AssertActionRedirect() .ToAction <WorkgroupController>(a => a.VendorList(1)); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(15, result.RouteValues["id"]); Assert.AreEqual("Cannot edit KFS Vendors. Please delete the vendor and add a new vendor.", Controller.ErrorMessage); WorkgroupVendorRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <WorkgroupVendor> .Is.Anything)); #endregion Assert }