Esempio n. 1
0
        public void HttpGet_IndexMethod_ReturnsExpectedList()
        {
            // build our service and controller
            serviceMocker.Setup(e => e.GetList()).Returns(() =>
            {
                var customers = new List <Customer>();
                for (int i = 1; i <= 100; i++)
                {
                    // need to set the ID and all reference fields, or the converter
                    // instance will get super sad because it expectes reference types (except strings)
                    // to be initliazed.
                    customers.Add(new Customer
                    {
                        Id             = i,
                        BillingAddress = new Address(),
                        StreetAddress  = new Address(),
                        PrimaryContact = new HumanContact()
                    });
                }
                return(customers);
            });

            // result is expected type
            var result = controller.Index();

            Assert.That(result, Is.InstanceOf <ViewResult>());

            // and it's viewmodel is what we expect
            var viewResult = (ViewResult)result;

            Assert.That(viewResult.Model, Is.InstanceOf <IEnumerable <CustomerViewModel> >());

            // and that the viewmodel has the number of elements that we're expecting
            var viewResultModel = (IEnumerable <CustomerViewModel>)viewResult.Model;

            Assert.That(viewResultModel.Count(), Is.EqualTo(service.GetList().Count()));
        }