public async Task UpdatePersonalDataShouldUpdateUser()
        {
            var dbContext         = MockServices.DbContextMock();
            var authService       = MockServices.AuthenticationServiceMock().Object;
            var userId            = authService.UserId;
            var unmodifiedUser    = dbContext.Users.Single(x => x.Id == userId);
            var expectedFirstName = unmodifiedUser.FirstName;

            dbContext.Entry(unmodifiedUser).State = Microsoft.EntityFrameworkCore.EntityState.Detached;

            var target = CreateAccountManagementService(dbContext);


            var userUpdateModel = new UserUpdateModel
            {
                Email    = "*****@*****.**",
                LastName = "12343"
            };

            var actual = await target.UpdatePersonalData(userUpdateModel);

            var user = dbContext.Users.Single(x => x.Id == userId);

            Assert.AreEqual(userUpdateModel.Email, actual.Email);
            Assert.AreEqual(userUpdateModel.LastName, actual.LastName);
            Assert.AreEqual(expectedFirstName, user.FirstName);
        }
Example #2
0
        public void Init()
        {
            mocks = new MockRepository();

            MockServices services = new MockServices();

            services.ViewSourceLoader = new FileAssemblyViewSourceLoader("Views");
            services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);

            viewComponentFactory = new DefaultViewComponentFactory();
            viewComponentFactory.Initialize();
            services.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            controller        = mocks.DynamicMock <IController>();
            engineContext     = new MockEngineContext(new UrlInfo("", "Home", "Index", "/", "castle"));
            controllerContext = new ControllerContext();

            factory = new SparkViewFactory();
            factory.Service(services);

            engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            manager = new DefaultViewEngineManager();
            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
        }
        public async Task CreatingVaultForAuthenticatedUserShouldSucceed()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock().Object;

            var target = new VaultCreationService(authenticationService, MockServices.EntityRepositoryMock(dbContext), dbContext, MockServices.HashServiceMock().Object);

            var vaultCreateModel = new VaultCreateModel
            {
                MasterKey = "555",
                Name      = "555"
            };

            var vaultId = await target.CreateVaultForAuthenticatedUser(vaultCreateModel);

            var vault      = dbContext.Vaults.Single(x => x.Id == vaultId);
            var vaultOwner = dbContext.VaultOwners.Single(x => x.VaultId == vaultId);
            var user       = dbContext.Users.Single(x => x.OwnerId == vaultOwner.OwnerId);

            var vaultOwnerRightsCount = dbContext.VaultOwnerRights.Where(x => x.VaultOwnerId == vaultOwner.Id).Count();

            Assert.AreEqual(authenticationService.UserId, user.Id);
            Assert.AreEqual(4, vaultOwnerRightsCount);
            Assert.AreEqual(vaultCreateModel.MasterKey, vault.MasterKey);
            Assert.AreEqual(vaultCreateModel.Name, vault.Name);
        }
		public void Init()
		{
			mocks = new MockRepository();

			MockServices services = new MockServices();
			services.ViewSourceLoader = new FileAssemblyViewSourceLoader("Views");
			services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);

			viewComponentFactory = new DefaultViewComponentFactory();
			viewComponentFactory.Initialize();
			services.AddService(typeof(IViewComponentFactory), viewComponentFactory);
			services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

			controller = mocks.DynamicMock<IController>();
			engineContext = new MockEngineContext(new UrlInfo("", "Home", "Index", "/", "castle"));
			controllerContext = new ControllerContext();

			factory = new SparkViewFactory();
			factory.Service(services);

			engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory);
			engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

			manager = new DefaultViewEngineManager();
			manager.RegisterEngineForExtesionLookup(factory);
			manager.RegisterEngineForView(factory);

		}
Example #5
0
        public async Task ValidVaultForUserShouldReturn()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock().Object;

            var target = new VaultInformationService(authenticationService, dbContext);

            var validVaultId = MockEntities.TestVault().Id;

            var actual = await target.GetVaultForAuthorizedUser(validVaultId);

            Assert.AreEqual(validVaultId, actual.Id);
        }
 public Inject Dependencies(IEnumerable <Warehouse> supply, IEnumerable <Demand> demand, IEnumerable <StockAlternative> stockAlternatives, IConfirmationInteraction refreshConfirmation = null, IConfirmationInteraction extendedTimelineConfirmation = null)
 {
     return(new Inject()
     {
         Services = new MockServices(supply, demand, stockAlternatives, refreshConfirmation, extendedTimelineConfirmation),
         Lookup = new Lookup()
         {
             PartKeyToCachedParts = new Dictionary <string, Inventory>(),
             PartkeyToStockcode = new Dictionary <string, string>(),
             DaysRemainingToCompletedJobs = new Dictionary <int, HashSet <Job> >(),
             .
             .
             .
         },
Example #7
0
        public async Task ValidVaultForDifferentUserShouldNotFound()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock();

            authenticationService.Setup(x => x.UserId).Returns(777);

            var target = new VaultInformationService(authenticationService.Object, dbContext);

            var validVaultId = MockEntities.TestVault().Id;
            var validUserId  = MockEntities.TestUser().Id;

            await Assert.ThrowsExceptionAsync <StatusCodeException>(async() => await target.GetVaultForAuthorizedUser(validVaultId));
        }
Example #8
0
        public static List <CustomerModel> GetCustomer(string parameter = null)
        {
            FetchInput input = new FetchInput();

            if (parameter != null)
            {
                return new List <CustomerModel>()
                       {
                           MockServices.ReturnMappedCustomerData_Mock(parameter)
                       }
            }
            ;
            else
            {
                return(MockServices.ReturnMappedCustomerData_Mock());
            }
        }
        private static AccountManagementService CreateAccountManagementService(Domain.FsDbContext dbContext, IVerificationService verificationService = null)
        {
            var entityRepostitory       = MockServices.EntityRepositoryMock(dbContext);
            var hashServiceMock         = MockServices.HashServiceMock().Object;
            var mailService             = MockServices.MailServiceMock().Object;
            var authenticationService   = MockServices.AuthenticationServiceMock().Object;
            var verificationServiceMock = verificationService ?? MockServices.VerificationServiceMock().Object;

            var target = new AccountManagementService(
                entityRepostitory,
                hashServiceMock,
                mailService,
                dbContext,
                authenticationService,
                verificationServiceMock);

            return(target);
        }
        public async Task CreatingVaultForUnAuthenticatedUserShouldFail()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationServiceMock = MockServices.AuthenticationServiceMock();

            authenticationServiceMock.Setup(x => x.IsAuthenticated).Returns(false);

            var target = new VaultCreationService(authenticationServiceMock.Object, MockServices.EntityRepositoryMock(dbContext), dbContext, MockServices.HashServiceMock().Object);

            var vaultCreateModel = new VaultCreateModel
            {
                MasterKey = "555",
                Name      = "555"
            };

            await Assert.ThrowsExceptionAsync <StatusCodeException>(async() => await target.CreateVaultForAuthenticatedUser(vaultCreateModel));
        }
        public async Task RegistrationFlowShouldWork()
        {
            var registrationModel = new UserRegistrationModel
            {
                ConfirmationUrl = "https://test.nl",
                Email           = "*****@*****.**",
                FirstName       = "servicetest",
                LastName        = "servicetest",
                Password        = "******",
                Username        = "******"
            };

            var dbContext = MockServices.DbContextMock();
            var verificationServiceMock = MockServices.VerificationServiceMock();

            verificationServiceMock.Setup(x => x.ValidateVerificationKey(It.IsAny <string>(), It.IsAny <UserVerificationType>())).ReturnsAsync(() =>
            {
                return(dbContext.Users.SingleAsync(x => x.Email == registrationModel.Email).Result);
            });

            var target = CreateAccountManagementService(dbContext, verificationServiceMock.Object);



            var result = await target.Register(registrationModel);

            var userPart1 = dbContext.Users.Single(x => x.Username == registrationModel.Username);

            Assert.IsFalse(userPart1.IsEmailConfirmed);

            dbContext.Entry(userPart1).State = Microsoft.EntityFrameworkCore.EntityState.Detached;

            var fakeKey = "dsfsfd";
            await target.ConfirmEmail(fakeKey);

            var user = dbContext.Users.Single(x => x.Username == registrationModel.Username);

            Assert.IsNotNull(user);
            Assert.AreEqual(registrationModel.Password, user.Password);
            Assert.IsTrue(user.IsEmailConfirmed);
            Assert.IsNotNull(user.Owner);
        }
Example #12
0
        public async Task ShouldReturnAllVaultForUser()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock().Object;


            var target = new VaultInformationService(authenticationService, dbContext);

            var validVaultId = MockEntities.TestVault().Id;
            var validUserId  = MockEntities.TestUser().Id;

            var vaults = await target.GetVaultsForAuthorizedUser();

            var expectedids = await dbContext.Vaults.Where(x => x.Owners.Any(y => y.OwnerId == authenticationService.UserId)).Select(x => x.Id).ToListAsync();

            var actualIds = vaults.Select(x => x.Id).ToList();

            CollectionAssert.AreEqual(expectedids, actualIds);
        }
		public void SetUp()
		{
			string viewPath = Path.Combine(SiteRoot, "Views");
			Layout = null;
			PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
			Helpers = new HelperDictionary();
			MockServices services = new MockServices();
			services.UrlBuilder = new DefaultUrlBuilder(new MockServerUtility(), new MockRoutingEngine());
			services.UrlTokenizer = new DefaultUrlTokenizer();
			UrlInfo urlInfo = new UrlInfo(
				"example.org", "test", "/TestBrail", "http", 80,
				"http://test.example.org/test_area/test_controller/test_action.tdd",
				Area, ControllerName, Action, "tdd", "no.idea");
			MockEngineContext = new MockEngineContext(new MockRequest(), new MockResponse(), services,
													  urlInfo);
			MockEngineContext.AddService<IUrlBuilder>(services.UrlBuilder);
			MockEngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer);
			MockEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory);
			MockEngineContext.AddService<ILoggerFactory>(new ConsoleFactory());
			MockEngineContext.AddService<IViewSourceLoader>(new FileAssemblyViewSourceLoader(viewPath));
			

			ViewComponentFactory = new DefaultViewComponentFactory();
			ViewComponentFactory.Service(MockEngineContext);
			ViewComponentFactory.Initialize();

			ControllerContext = new ControllerContext();
			ControllerContext.Helpers = Helpers;
			ControllerContext.PropertyBag = PropertyBag;
			MockEngineContext.CurrentControllerContext = ControllerContext;


			Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(MockEngineContext);
			Helpers["htmlhelper"] = Helpers["html"] = new HtmlHelper(MockEngineContext);
			Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(MockEngineContext);
			Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(MockEngineContext);


			//FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader(viewPath);
//			loader.AddAssemblySource(
//				new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName,
//									   "Castle.MonoRail.Views.Brail.Tests.ResourcedViews"));

			viewEngine = new AspViewEngine();
			viewEngine.Service(MockEngineContext);
			AspViewEngineOptions options = new AspViewEngineOptions();
			options.CompilerOptions.AutoRecompilation = true;
			options.CompilerOptions.KeepTemporarySourceFiles = false;
			string root = AppDomain.CurrentDomain.BaseDirectory;
			root = root.Substring(0, root.LastIndexOf("Bin\\Debug", StringComparison.InvariantCultureIgnoreCase));
			ICompilationContext context = 
				new CompilationContext(
					new DirectoryInfo(root + @"\Bin\Debug"),
					new DirectoryInfo(root),
					new DirectoryInfo(root + @"\RenderingTests\Views"),
					new DirectoryInfo(root));
			viewEngine.Initialize(context, options);
			System.Console.WriteLine("init");

			BeforEachTest();
		}
Example #14
0
        public void SetUp()
        {
            string viewPath = Path.Combine(SiteRoot, "Views");

            Layout      = null;
            PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            Helpers     = new HelperDictionary();
            MockServices services = new MockServices();

            services.UrlBuilder   = new DefaultUrlBuilder(new MockServerUtility(), new MockRoutingEngine());
            services.UrlTokenizer = new DefaultUrlTokenizer();
            UrlInfo urlInfo = new UrlInfo(
                "example.org", "test", "/TestBrail", "http", 80,
                "http://test.example.org/test_area/test_controller/test_action.tdd",
                Area, ControllerName, Action, "tdd", "no.idea");

            MockEngineContext = new MockEngineContext(new MockRequest(), new MockResponse(), services,
                                                      urlInfo);
            MockEngineContext.AddService <IUrlBuilder>(services.UrlBuilder);
            MockEngineContext.AddService <IUrlTokenizer>(services.UrlTokenizer);
            MockEngineContext.AddService <IViewComponentFactory>(ViewComponentFactory);
            MockEngineContext.AddService <ILoggerFactory>(new ConsoleFactory());
            MockEngineContext.AddService <IViewSourceLoader>(new FileAssemblyViewSourceLoader(viewPath));


            ViewComponentFactory = new DefaultViewComponentFactory();
            ViewComponentFactory.Service(MockEngineContext);
            ViewComponentFactory.Initialize();

            ControllerContext             = new ControllerContext();
            ControllerContext.Helpers     = Helpers;
            ControllerContext.PropertyBag = PropertyBag;
            MockEngineContext.CurrentControllerContext = ControllerContext;


            Helpers["urlhelper"]        = Helpers["url"] = new UrlHelper(MockEngineContext);
            Helpers["htmlhelper"]       = Helpers["html"] = new HtmlHelper(MockEngineContext);
            Helpers["dicthelper"]       = Helpers["dict"] = new DictHelper(MockEngineContext);
            Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(MockEngineContext);


            //FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader(viewPath);
//			loader.AddAssemblySource(
//				new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName,
//									   "Castle.MonoRail.Views.Brail.Tests.ResourcedViews"));

            viewEngine = new AspViewEngine();
            viewEngine.Service(MockEngineContext);
            AspViewEngineOptions options = new AspViewEngineOptions();

            options.CompilerOptions.AutoRecompilation        = true;
            options.CompilerOptions.KeepTemporarySourceFiles = false;
            string root = AppDomain.CurrentDomain.BaseDirectory;

            root = root.Substring(0, root.LastIndexOf("Bin\\Debug", StringComparison.InvariantCultureIgnoreCase));
            ICompilationContext context =
                new CompilationContext(
                    new DirectoryInfo(root + @"\Bin\Debug"),
                    new DirectoryInfo(root),
                    new DirectoryInfo(root + @"\RenderingTests\Views"),
                    new DirectoryInfo(root));

            viewEngine.Initialize(context, options);
            System.Console.WriteLine("init");

            BeforEachTest();
        }