Beispiel #1
0
        public void TestMethod2()
        {
            var mockSet = new Mock <DbSet <Address> >();

            var mockContext = new Mock <AddressContext>();

            mockContext.Setup(m => m.Addresses).Returns(mockSet.Object);

            var mockRepository = new Mock <AddressRepository>(mockContext.Object);

            var contlloer = new AddressController(mockRepository.Object);

            contlloer.Add(new Address());

            mockSet.Verify(m => m.Add(It.IsAny <Address>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
        public async Task Cannot_Add_Invalid_Address()
        {
            AddressController addressCtrl = new AddressController(addressRepo);

            addressCtrl.ModelState.AddModelError("error", "error message");
            ViewResult result = await addressCtrl.Add(new ShoppingAddress
            {
                ShoppingAddressID = 11,
                UserID            = "#939521",
                Line1             = "Pine Rd"
            }) as ViewResult;

            Assert.IsNotNull(result);

            ShoppingAddress address = (ShoppingAddress)result.Model;

            Assert.AreEqual(11, address.ShoppingAddressID);
        }
        public async Task Can_Add_Valid_Address()
        {
            AddressController     addressCtrl = new AddressController(addressRepo);
            RedirectToRouteResult result      = await addressCtrl.Add(new ShoppingAddress
            {
                ShoppingAddressID = 12,
                UserID            = "#939521",
                Line1             = "Pine Rd",
                City    = "New York",
                State   = "NY",
                Country = "US",
                Zip     = "77823"
            }) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Confirm", result.RouteValues["action"]);
            Assert.AreEqual("Order", result.RouteValues["controller"]);
            Assert.AreEqual(12, result.RouteValues["addressId"]);
        }
 public void AddTest()
 {
     IFormsAuthentication formsAuthentication = null; // TODO: Initialize to an appropriate value
     IAddressService addressService = null; // TODO: Initialize to an appropriate value
     AddressController target = new AddressController(formsAuthentication, addressService); // TODO: Initialize to an appropriate value
     DeliveryAddressDetails view = null; // TODO: Initialize to an appropriate value
     JsonResult expected = null; // TODO: Initialize to an appropriate value
     JsonResult actual;
     actual = target.Add(view);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
        public void ShouldBeAbleToAddDeliveryAddress()
        {
            // arrange
            var controller = new AddressController(this.formsAuthentication, this.addressService);
            var viewModel = new DeliveryAddressViewModel
                {
                    Id = 0,
                    AddressName = "Test 1",
                    AddressLine1 = "street",
                    AddressLine2 = "flat",
                    City = "Minsk",
                    CountryCode = "BY",
                    Region = null,
                    State = null,
                    FirstName = "Vitali",
                    LastName = "Hatalski",
                    Phone = null,
                    ZipCode = "1233",
                    AddressLine3 = null
                };

            // act
            var actual = controller.Add(viewModel) as JsonNetResult;

            // assert
            Assert.That(actual, Is.Not.Null);
            Debug.Assert(actual != null, "actual != null");
            var model = actual.Data as DeliveryAddressViewModel;
            Debug.Assert(model != null, "model != null");
            Assert.That(model.MessageType, Is.EqualTo("Success"));
            Assert.That(model.Id, Is.GreaterThan(0));
            Assert.That(model.AddressName, Is.EqualTo("Test 1"));
            Assert.That(model.AddressLine1, Is.EqualTo("street"));
            Assert.That(model.AddressLine2, Is.EqualTo("flat"));
            Assert.That(model.AddressLine3, Is.Null);
            Assert.That(model.City, Is.EqualTo("Minsk"));
            Assert.That(model.CountryCode, Is.EqualTo("BY"));
            Assert.That(model.Region, Is.Null);
            Assert.That(model.State, Is.Null);
            Assert.That(model.FirstName, Is.EqualTo("Vitali"));
            Assert.That(model.LastName, Is.EqualTo("Hatalski"));
            Assert.That(model.Phone, Is.Null);
            Assert.That(model.ZipCode, Is.EqualTo("1233"));
        }