Esempio n. 1
0
        public void IndexViewShouldReturnListOfAssetTypes()
        {
            // Arrange
            IEnumerable <AssetType> assettypes = new List <AssetType>()
            {
                new AssetType {
                    Id = 1, Comments = "test", OwnerId = "123", TypeName = "type1"
                },
                new AssetType {
                    Id = 1, Comments = "test", OwnerId = "123", TypeName = "type2"
                },
            };

            Mapper.Initialize(cfg => cfg.AddProfile <AutoMapperProfile>());
            var fakeUOW       = new Mock <IUnitOfWork>();
            var fakeAssetRepo = new Mock <IGenericRepository <AssetType> >();

            fakeAssetRepo.Setup(x =>
                                x.GetAll(It.IsAny <Expression <Func <AssetType, bool> > >(), It.IsAny <Expression <Func <AssetType, object> >[]>()))
            .Returns(assettypes);
            fakeUOW.Setup(x => x.AssetTypes).Returns(fakeAssetRepo.Object);

            var sut = new AssetTypesController(fakeUOW.Object);

            // act and assert
            sut.WithCallTo(x => x.Index())
            .ShouldRenderDefaultView()
            .WithModel <IEnumerable <AssetTypeViewModel> >(x => x.Count() == 2);
        }
Esempio n. 2
0
        public void CreateReturnsDefaultView()
        {
            // Arrange
            var fakeUOW = new Mock <IUnitOfWork>();

            var sut = new AssetTypesController(fakeUOW.Object);

            // act and assert
            sut.WithCallTo(x => x.Create())
            .ShouldRenderDefaultView();
        }
Esempio n. 3
0
        public void CreateWithValidModelShouldCreateAssetTypeAndRedirectToIndex()
        {
            // Arrange
            AssetTypeViewModel assetType = new AssetTypeViewModel
            {
                Comments = "test",
                TypeName = "debt"
            };

            string       username = "******";
            string       userid   = Guid.NewGuid().ToString("N"); //could be a constant
            List <Claim> claims   = new List <Claim> {
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", username),
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", userid)
            };
            var genericIdentity = new GenericIdentity("");

            genericIdentity.AddClaims(claims);
            var genericPrincipal  = new GenericPrincipal(genericIdentity, new string[] { "Asegurado" });
            var controllerContext = new Mock <ControllerContext>();

            controllerContext.SetupGet(x => x.HttpContext.User).Returns(genericPrincipal);

            Mapper.Initialize(cfg => cfg.AddProfile <AutoMapperProfile>());

            var fakeUOW       = new Mock <IUnitOfWork>();
            var fakeAssetRepo = new Mock <IGenericRepository <AssetType> >();

            fakeUOW.Setup(x => x.AssetTypes).Returns(fakeAssetRepo.Object);
            var sut = new AssetTypesController(fakeUOW.Object);

            sut.ControllerContext = controllerContext.Object;

            // act and assert
            sut.WithCallTo(x => x.Create(assetType))
            .ShouldRedirectTo(x => x.Index);
            fakeAssetRepo.Verify(x => x.Add(It.IsAny <AssetType>()), Times.Once());
        }