コード例 #1
0
        public async Task ShouldGetEditPage()
        {
            //Arrange
            var guid             = Guid.NewGuid();
            var mock             = new Mock <IFundManagerRepository>();
            var fundManagerModel = new FundManager();

            mock.SetupAllProperties();
            mock.Setup(m => m.Get(guid)).Returns(Task.FromResult(fundManagerModel));
            var mockFundRepo = new Mock <IFundRepository>();
            IEnumerable <Fund> emptyFunds = new List <Fund>();

            mockFundRepo.Setup(m => m.GetFunds(new Guid()))
            .Returns(Task.FromResult(emptyFunds))
            .Verifiable();
            var controller = new FundManagerController(mock.Object, mockFundRepo.Object);
            var expected   = new FundManager().ToExpectedObject();

            //Act
            var actual = await controller.Edit(guid);

            //Assert
            Assert.That(actual, Is.TypeOf <ViewResult>());
            mock.Verify();
            Assert.That(((ViewResult)actual).Model, Is.EqualTo(expected));
        }
コード例 #2
0
        public async Task ShouldGetRedirectedToErrorFromEditPageIfNullGuid()
        {
            //Arrange
            var validGuid        = Guid.NewGuid();
            var mock             = new Mock <IFundManagerRepository>();
            var fundManagerModel = new FundManager();

            mock.SetupAllProperties();
            mock.Setup(m => m.Get(validGuid)).Returns(Task.FromResult(fundManagerModel));
            var mockFundRepo = new Mock <IFundRepository>();
            IEnumerable <Fund> emptyFunds = new List <Fund>();

            mockFundRepo.Setup(m => m.GetFunds(new Guid()))
            .Returns(Task.FromResult(emptyFunds))
            .Verifiable();
            var controller = new FundManagerController(mock.Object, mockFundRepo.Object);

            //Act
            var actual = await controller.Edit((Guid?)null);

            //Assert
            Assert.That(actual, Is.TypeOf <RedirectToRouteResult>());
            var redir = (RedirectToRouteResult)actual;

            Assert.That("errorMessage", Is.EqualTo(redir.RouteValues.Keys.First()));
            mock.Verify();
        }
コード例 #3
0
        public async void ShouldGetRedirectedToErrorFromEditPageIfNullGuid()
        {
            var validGuid        = Guid.NewGuid();
            var mock             = new Mock <IFundManagerRepository>();
            var fundManagerModel = new FundManager();

            mock.SetupAllProperties();
            mock.Setup(m => m.Get(validGuid)).Returns(Task.FromResult(fundManagerModel));
            var controller = new FundManagerController(mock.Object);

            var result = await controller.Edit((Guid?)null);

            Assert.That(result, Is.TypeOf <RedirectToRouteResult>());
            mock.Verify();
        }
コード例 #4
0
        public async void ShouldGetEditPage()
        {
            var guid             = Guid.NewGuid();
            var mock             = new Mock <IFundManagerRepository>();
            var fundManagerModel = new FundManager();

            mock.SetupAllProperties();
            mock.Setup(m => m.Get(guid)).Returns(Task.FromResult(fundManagerModel));
            var controller = new FundManagerController(mock.Object);

            var result = await controller.Edit(guid);

            Assert.That(result, Is.TypeOf <ViewResult>());
            mock.Verify();
            Assert.That(((ViewResult)result).Model, Is.EqualTo(fundManagerModel));
        }
コード例 #5
0
        public async void ShouldEditFundManage()
        {
            var guid = Guid.NewGuid();
            var mock = new Mock <IFundManagerModelRepository>();
            var fm   = new FundManagerModel()
            {
                Id           = guid,
                Biography    = "Some1",
                Location     = Location.London,
                ManagedSince = DateTime.Now,
                Name         = "Fred1"
            };

            mock.Setup(m => m.Update(fm)).Returns(Task.FromResult(fm));
            var controller = new FundManagerController(mock.Object);
            var result     = await controller.Edit(fm);

            Assert.That(result, Is.TypeOf <ViewResult>());
            mock.Verify();
            Assert.That(((ViewResult)result).Model, Is.EqualTo(fm));
        }