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 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 }