コード例 #1
0
        public async Task ShouldGetRedirectedToErrorFromDeletePageIfNullGuid()
        {
            //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.Delete(null);

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

            Assert.That("errorMessage", Is.EqualTo(redir.RouteValues.Keys.First()));
            mock.Verify();
        }
コード例 #2
0
        public async Task ShouldGetIndexPageIfSuccessfulDelete()
        {
            //Arrange
            var validGuid = Guid.NewGuid();
            var mock      = new Mock <IFundManagerRepository>();

            mock.SetupAllProperties();
            mock.Setup(m => m.Delete(validGuid)).Returns(Task.FromResult(true));
            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.Delete(validGuid);


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

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

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

            var result = await controller.Delete(validGuid);

            Assert.That(result, Is.TypeOf <RedirectToRouteResult>());
            mock.Verify();
        }
コード例 #4
0
        public async void ShouldGetRedirectedToErrorFromDeletePageIfNullGuid()
        {
            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.Delete(null);

            Assert.That(result, Is.TypeOf <RedirectToRouteResult>());
            mock.Verify();
        }