Exemplo n.º 1
0
        public SetupModule(IAggregateRootRepository repository,
                           IAccountRepository accountRepository,
                           IIdGenerator idGenerator)
            :base("/setup")
        {
            Get["/"] = _ =>
            {
                if (accountRepository.Count() > 0)
                    return HttpStatusCode.NotFound;

                return View["Index"];
            };

            Post["/"] = _ =>
            {
                var model = this.Bind<CreateModel>();

                if (accountRepository.Count() > 0)
                    return HttpStatusCode.NotFound;

                var account = new Domain.Account(idGenerator.NextGuid(),
                    model.Name, model.FirstName, model.LastName, model.Email);

                account.ChangePassword(model.Password);
                account.MakeAdmin();

                repository.Save(account);

                return Response.AsRedirect("/");
            };
        }
Exemplo n.º 2
0
        static Context()
        {
            // drop old databases

            new MongoContext(ConfigurationManager.ConnectionStrings["MongoConnectionReadModel"].ConnectionString)
                .GetDatabase().Drop();

            new MongoContext(ConfigurationManager.ConnectionStrings["MongoConnectionEventStore"].ConnectionString)
                .GetDatabase().Drop();

            _bootstrapper = new NancyTestBootstrapper();
            new Browser(_bootstrapper);

            using (var container = _bootstrapper.CreateContainer())
            {
                var account = new Domain.Account(Guid.NewGuid(),
                    "John Doe BVBA", "John", "Doe", "*****@*****.**");
                var accountAdmin = new Domain.Account(Guid.NewGuid(),
                    "Jane Doe BVBA", "Jane", "Doe", "*****@*****.**");

                account.ChangePassword("john");
                accountAdmin.ChangePassword("jane");
                accountAdmin.MakeAdmin();

                container.Resolve<IAggregateRootRepository>().Save(account);
                container.Resolve<IAggregateRootRepository>().Save(accountAdmin);
            }
        }