Ejemplo n.º 1
0
        public void TestMethod2()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Family.Insert(Id: 1, Name: "fam1");
            db.Family.Insert(Id: 2, Name: "fam2");

            var facade = new DbFacade();
            var families = facade.GetFamilies();

            Assert.AreEqual(families.Count, 2);
            foreach (var item in families)
            {
                if (item.Id == 1)
                {
                    Assert.AreEqual("fam1", item.Name);
                }
                else
                {
                    Assert.AreEqual("fam2", item.Name);
                }
            }
        }
Ejemplo n.º 2
0
 public TodoBootStrap ConfigureDatabaseForTest()
 {
     var Adapter = new InMemoryAdapter();
     Adapter.SetKeyColumn("Todo", "TableName");
     Database.UseMockAdapter(Adapter);
     return this;
 }
Ejemplo n.º 3
0
 private static void InitInMemoryTestDatabase()
 {
     Adapter = CreateAdapter();
     Database.UseMockAdapter(Adapter);
     DB = Database.Open();
     InitDatastructure();
 }
Ejemplo n.º 4
0
        public void Creates_user_when_valid_data_is_posted()
        {
            const string login = "******";
            const string password = "******";

            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var browser = new Browser(BootstrapperFactory.Create());

            var response = browser.Post("/admin/setup", with =>
            {
                with.HttpRequest();
                with.FormValue("Login", login);
                with.FormValue("Password", password);
            });

            var db = Database.Open();

            var allUsers = db.Users.All().ToList();

            Assert.AreEqual(1, allUsers.Count);
            Assert.AreEqual(login, allUsers[0].Login);
            Assert.AreEqual(password + "salt", allUsers[0].HashedPassword);
            Assert.AreEqual("salt", allUsers[0].Salt);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Ejemplo n.º 5
0
        public void AddDraft_adds_draft_to_the_database_when_title_is_valid()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Posts", "PostId");
            adapter.SetAutoIncrementColumn("Posts", "PostId");
            Database.UseMockAdapter(adapter);

            var slugifier = A.Fake<ISlugifier>();
            var slugManager = A.Fake<ISlugManager>();

            A.CallTo(() => slugifier.Slugify("the title")).Returns("the-title");
            A.CallTo(() => slugManager.GetUniqueSlug("the-title")).Returns("the-title");

            var postStore = new PostStore(slugifier, slugManager);

            postStore.AddDraft("the title");

            var db = Database.Open();
            var post = db.Posts.Get(1);

            Assert.AreEqual(1, post.PostId);
            Assert.AreEqual("the title", post.Title);
            Assert.AreEqual("the-title", post.UrlSlug);
            Assert.IsFalse(post.IsPublished);
        }
 public void SetUp()
 {
     log = new Mock<ILogger>();
     sut = new SimpleDataModificator(log.Object);
     var adapter = new InMemoryAdapter();
     Database.UseMockAdapter(adapter);
 }
 public void SetUp()
 {
     timeContext = Substitute.For<TimeContext>();
     sut = new SimpleDataModificator(timeContext);
     reader = new SimpleDataRepresentator();
     var adapter = new InMemoryAdapter();
     Database.UseMockAdapter(adapter);
 }
        public void Setup()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);
            _db = Database.Open();
            var repo = new SQLServerDeviationRepository(_db);

            _controllerUndertest = new ReporterController(repo);
        }
        public void DBInit()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Contact", "Id");
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Contact.Insert(Id: 1, FirstName: "Jana", LastName: "K", Title: "Mr", Status: "Active");
            db.Contact.Insert(Id: 2, FirstName: "Test", LastName: "User", Title: "Miss", Status: "Active");
        }
 protected SimpleDataPersistenceEngine CreateSut()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Aggregates", "AggregateId");
     adapter.SetAutoIncrementColumn("EventsLog", "Sequence");
     Database.UseMockAdapter(adapter);
     var binarySerializer = new BinarySerializer();
     var sut = new SimpleDataPersistenceEngine(string.Empty, binarySerializer);
     return sut;
 }
Ejemplo n.º 11
0
        public void Returns_null_when_guid_is_not_found()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var userMapper = new UserMapper();
            var identity = userMapper.GetUserFromIdentifier(Guid.NewGuid(), null);

            Assert.IsNull(identity);
        }
Ejemplo n.º 12
0
 public MusicStoreBootStrap ConfigureDatabaseForTest()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("AdminUser", "UserName");
     adapter.SetKeyColumn("Products", "Id");
     adapter.SetKeyColumn("Cart", "Id");
     adapter.SetKeyColumn("CartItem", "CartId");
     Database.UseMockAdapter(adapter);
     return this;
 }
 public void SetUp()
 {
     sut = new SimpleDataRepresentator();
     timeContext = Substitute.For<TimeContext>();
     tesеTime = new DateTime(2014, 10, 10);
     timeContext.Now().Returns(tesеTime);
     writer = new SimpleDataModificator(timeContext);
     var adapter = new InMemoryAdapter();
     Database.UseMockAdapter(adapter);
 }
        public void BeforeEachScenario()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetAutoIncrementKeyColumn("FairyTaleFigure", "ID");
            adapter.Join
                .Master("FairyTaleFigure", "ID")
                .Detail("FairyTaleFigure", "Hangarounds");

            Database.UseMockAdapter(adapter);
            ScenarioContext.Current.Set(Database.Open(), ScenarioContextKeys.DB);
        }
Ejemplo n.º 15
0
        public void Returns_view_when_no_users_exists()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var browser = new Browser(BootstrapperFactory.Create());

            var response = browser.Get("/admin/setup", with => with.HttpRequest());

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
 public void CanUseSimpleDataMockingFunctionalityInTestMode()
 {
     var mockAdapter = new InMemoryAdapter();
     mockAdapter.Insert("Users", new Dictionary<string, object> { { "Id", 1 }, { "Name", "Albert" } }, false);
     Database.UseMockAdapter(mockAdapter);
     var helper = new SimpleDataRepositoryHelper(Database.Open());
     var rowsList = helper.GetUsers().ToList();
     Assert.AreEqual(1, rowsList.Count);
     Assert.AreEqual(1, rowsList[0].Id);
     Assert.AreEqual("Albert", rowsList[0].Name);
 }
Ejemplo n.º 17
0
        public void Redirects_to_setup_when_no_user_exists()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var browser = new Browser(BootstrapperFactory.Create());

            var response = browser.Get("/admin/login", with => with.HttpRequest());

            response.ShouldHaveRedirectedTo("/admin/setup");
        }
Ejemplo n.º 18
0
        public void Returns_same_string_when_database_is_empty()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var slugManager = new SlugManager();

            var input = "a-new-slug";
            var uniqueSlug = slugManager.GetUniqueSlug(input);

            Assert.AreEqual(input, uniqueSlug);
        }
        public SimpleDataTests()
        {
            // Con  figure the simple data InMemoryTest database
            // to have the properties we need to test it
            var adapter = new InMemoryAdapter();
            adapter.SetAutoIncrementKeyColumn("FairyTaleFigure", "ID");
            adapter.Join
                .Master("FairyTaleFigure", "ID")
                .Detail("FairyTaleFigure", "Hangarounds");

            Database.UseMockAdapter(adapter);
            _db = Database.Open();
        }
Ejemplo n.º 20
0
        public void Post_redirects_to_login_when_at_least_one_user_exists()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Users.Insert(Login: "******", HashedPassword: "******", Salt: "salt", Guid: "5240cdc7-f32c-4d7f-9d27-f76a4a87d881");

            var browser = new Browser(BootstrapperFactory.Create());

            var response = browser.Post("/admin/setup", with => with.HttpRequest());

            response.ShouldHaveRedirectedTo("/admin/login");
        }
Ejemplo n.º 21
0
        public void Returns_view_when_at_least_one_user_exists()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Users.Insert(Login: "******", HashedPassword: "******", Salt: "salt", Guid: "5240cdc7-f32c-4d7f-9d27-f76a4a87d881");

            var browser = new Browser(BootstrapperFactory.Create());

            var response = browser.Get("/admin/login", with => with.HttpRequest());

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
        public void SetUp()
        {
            log = new Mock<ILogger>().Object;
            sut = new SimpleDataRepresentator(log);
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Customers.Insert(CustomerId: 1, FirstName: "Mihail", LastName: "Podobivsky");
            db.Customers.Insert(CustomerId: 2, FirstName: "Joe", LastName: "Oraely");

            db.Licenses.Insert(LicenseId: 1, CustomerId: 1, Key: "lasdjflksdf", CreationDate: new DateTime(2011, 02, 02), ModificationDate: new DateTime(2011, 02, 02));
            db.Licenses.Insert(LicenseId: 2, CustomerId: 2, Key: "ghjfhgkfjhk", CreationDate: new DateTime(2011, 02, 02), ModificationDate: new DateTime(2011, 02, 02));
        }
Ejemplo n.º 23
0
        public void Add_returns_correct_json()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var postStore = A.Fake<IPostStore>();
            var addDraftResult = new AddDraftResult
                {
                    Id = 1,
                    Success = true,
                    Title = "The Title",
                    Url = "/admin/posts/edit/1"
                };

            A.CallTo(() => postStore.AddDraft("The Title")).Returns(addDraftResult);

            FakeRootPathProvider.RootPath = "../../../Markie";

            var bootstrapper = new ConfigurableBootstrapper(with =>
                {
                    with.RootPathProvider(new FakeRootPathProvider());
                    with.Dependency<FakePasswordService>();
                    with.Dependency(postStore);
                    with.RequestStartup((container, pipelines, context) =>
                        {
                            var formsAuthConfiguration = new FormsAuthenticationConfiguration()
                                {
                                    RedirectUrl = "~/admin/login",
                                    UserMapper = new UserMapper()
                                };

                            FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
                        });
                });
            var browser = new Browser(bootstrapper);

            var jsonResult = browser.Post("/admin/posts/add", with =>
                {
                    with.HttpRequest();
                    with.FormValue("title", "The Title");
                });

            var result = Newtonsoft.Json.JsonConvert.DeserializeObject<AddDraftResult>(jsonResult.Body.AsString());

            Assert.AreEqual(addDraftResult.Id, result.Id);
            Assert.AreEqual(addDraftResult.Success, result.Success);
            Assert.AreEqual(addDraftResult.Title, result.Title);
            Assert.AreEqual(addDraftResult.Url, result.Url);
        }
Ejemplo n.º 24
0
        public void Increments_slug_when_it_already_exists()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Posts.Insert(Title: "A title", UrlSlug: "a-slug", IsPublised: false, CreatedOn: DateTime.UtcNow, LastUpdatedOn: DateTime.UtcNow);

            var slugManager = new SlugManager();

            var input = "a-slug";
            var uniqueSlug = slugManager.GetUniqueSlug(input);

            Assert.AreEqual("a-slug-2", uniqueSlug);
        }
Ejemplo n.º 25
0
        public void Returns_same_string_when_slug_is_not_found()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Posts.Insert(Title: "A title", UrlSlug: "a-slug", IsPublised: false, CreatedOn: DateTime.UtcNow, LastUpdatedOn: DateTime.UtcNow);

            var slugManager = new SlugManager();

            var input = "a-new-slug";
            var uniqueSlug = slugManager.GetUniqueSlug(input);

            Assert.AreEqual(input, uniqueSlug);
        }
Ejemplo n.º 26
0
        public void Returns_useridenty_when_guid_is_found()
        {
            const string guid = "91e2403b-c568-4116-9c87-b6b71b6acbe4";
            const string userName = "******";

            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Users.Insert(Login: userName, HashedPassword: "******", Salt: "salt", Guid: guid);

            var userMapper = new UserMapper();
            var identity = userMapper.GetUserFromIdentifier(new Guid(guid), null);

            Assert.AreEqual(userName, identity.UserName);
        }
Ejemplo n.º 27
0
        private static InMemoryAdapter CreateAdapter()
        {
            var adapter = new InMemoryAdapter();

            adapter.SetKeyColumn("Users", "Id");
            adapter.SetAutoIncrementColumn("Users", "Id");

            adapter.SetKeyColumn("Kids", "Id");
            adapter.SetAutoIncrementColumn("Kids", "Id");

            adapter.SetKeyColumn("Quotes", "Id");
            adapter.SetAutoIncrementColumn("Quotes", "Id");

            adapter.ConfigureJoin("Users", "Id", "Kids", "Kids", "FamiliyId", "Parent");
            adapter.ConfigureJoin("Kids", "Id", "Quotes", "Quotes", "KidId", "Kid");

            return adapter;
        }
Ejemplo n.º 28
0
        public void TestMethod1()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);

            // Insert some test data
            var db = Database.Open();
            db.Test.Insert(Id: 1, Name: "Alice");

            // Act
            var record = db.Test.FindById(1);

            // Assert
            Assert.IsNotNull(record);
            Assert.AreEqual(1, record.Id);
            Assert.AreEqual("Alice", record.Name);
        }
Ejemplo n.º 29
0
        public void Redirects_when_login_succeeds()
        {
            var adapter = new InMemoryAdapter();
            Database.UseMockAdapter(adapter);

            var db = Database.Open();
            db.Users.Insert(Login: "******", HashedPassword: "******", Salt: "salt", Guid: "5240cdc7-f32c-4d7f-9d27-f76a4a87d881");

            var browser = new Browser(BootstrapperFactory.Create());

            var response = browser.Post("/admin/login", with =>
                {
                    with.HttpRequest();
                    with.FormValue("Login", "*****@*****.**");
                    with.FormValue("Password", "password");
                });

            response.ShouldHaveRedirectedTo("/admin/posts");
        }
Ejemplo n.º 30
0
        public void AddDraft_adds_nothing_to_the_database_when_title_is_empty_whitespace_or_null(string title)
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Posts", "PostId");
            adapter.SetAutoIncrementColumn("Posts", "PostId");
            Database.UseMockAdapter(adapter);

            var slugifier = A.Fake<ISlugifier>();
            var slugManager = A.Fake<ISlugManager>();

            var postStore = new PostStore(slugifier, slugManager);

            postStore.AddDraft(title);

            var db = Database.Open();
            var postCount = db.Posts.GetCount();

            Assert.AreEqual(0, postCount);
        }