Пример #1
0
        public void Setup()
        {
            repo = new InMemoryDeviationRepository();
            var adapter = new InMemoryAdapter();

            Database.UseMockAdapter(adapter);
        }
Пример #2
0
        public void Setup()
        {
            var adapter = new InMemoryAdapter();

            Database.UseMockAdapter(adapter);
            repo = new SQLServerDeviationRepository(Database.Open());
        }
Пример #3
0
        public async Task <List <Repository.Category> > GetCategories()
        {
            List <Repository.Category> lst = new List <Repository.Category>();

            if (VarsHelper.GetDataMode() == Enums.ModeType.SQLData)
            {
                lst = localdbRepository.Categories.ToList();
            }
            else if (VarsHelper.GetDataMode() == Enums.ModeType.InMemory)
            {
                lst = (List <Repository.Category>)InMemoryAdapter.Get(CATEGORIES);

                if (lst == null)
                {
                    lst = new List <Repository.Category>();
                    lst.Add(new Repository.Category()
                    {
                        Id = Guid.NewGuid().ToString(), Name = "Food"
                    });
                    lst.Add(new Repository.Category()
                    {
                        Id = Guid.NewGuid().ToString(), Name = "Shoes"
                    });
                    lst.Add(new Repository.Category()
                    {
                        Id = Guid.NewGuid().ToString(), Name = "Books"
                    });
                    InMemoryAdapter.Set <List <Repository.Category> >(CATEGORIES, lst);
                }
            }


            return(lst);
        }
Пример #4
0
        public void LeftJoinTest()
        {
            var adapter = new InMemoryAdapter();

            adapter.SetKeyColumn("Events", "Id");
            adapter.SetAutoIncrementColumn("Events", "Id");
            adapter.SetKeyColumn("Doors", "Id");
            adapter.SetAutoIncrementColumn("Doors", "Id");
            adapter.Join.Master("Events", "Id").Detail("Doors", "EventId");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Events.Insert(Id: 1, Code: "CodeMash2013", Name: "CodeMash 2013");
            db.Events.Insert(Id: 2, Code: "SomewhereElse", Name: "Some Other Conf");
            db.Doors.Insert(Id: 1, Code: "F7E08AC9-5E75-417D-A7AA-60E88B5B99AD", EventID: 1);
            db.Doors.Insert(Id: 2, Code: "0631C802-2748-4C63-A6D9-CE8C803002EB", EventID: 1);
            db.Doors.Insert(Id: 3, Code: "281ED88F-677D-49B9-84FA-4FAE022BBC73", EventID: 1);
            db.Doors.Insert(Id: 4, Code: "9DF7E964-1ECE-42E3-8211-1F2BF7054A0D", EventID: 2);
            db.Doors.Insert(Id: 5, Code: "9418123D-312A-4E8C-8807-59F0A63F43B9", EventID: 2);

            List <dynamic> actual = db.Doors.FindAll(db.Doors.Events.Code == "CodeMash2013")
                                    .Select(db.Doors.Id, db.Events.Name)
                                    .ToList();

            Assert.AreEqual(3, actual.Count);
        }
Пример #5
0
        public void BeforeEachScenario()
        {
            var adapter = new InMemoryAdapter();

            Database.UseMockAdapter(adapter);

            _db = Database.Open();
        }
Пример #6
0
        public void UpsertWithoutDefinedKeyColumnsShouldThrowMeaningfulException()
        {
            var adapter = new InMemoryAdapter();

            Database.UseMockAdapter(adapter);
            var db        = Database.Open();
            var exception = Assert.Throws <InvalidOperationException>(() => db.Test.Upsert(Id: 1, HasTowel: true));

            Assert.AreEqual("No key columns defined for table \"Test\"", exception.Message);
        }
Пример #7
0
 public void StopUsingMockAdapterStopsUsingMockAdapter()
 {
     var mock = new InMemoryAdapter();
     Database.UseMockAdapter(mock);
     Database db = Database.OpenNamedConnection("Mock");
     Assert.AreSame(mock, db.GetAdapter());
     Database.StopUsingMockAdapter();
     db = Database.OpenNamedConnection("Mock");
     Assert.IsInstanceOf<AdoAdapter>(db.GetAdapter());
 }
        public void Setup()
        {
            var adapter = new InMemoryAdapter();

            Database.UseMockAdapter(adapter);
            _db = Database.Open();
            var repo = new SQLServerDeviationRepository(_db);

            _controllerUndertest = new ReporterController(repo);
        }
Пример #9
0
        private static int ThreadTestHelper(int userId)
        {
            var mockAdapter = new InMemoryAdapter();

            Database.UseMockAdapter(mockAdapter);
            var db = Database.Open();

            db.Users.Insert(Id: userId, Email: "foo");
            return(Database.Default.Users.FindByEmail("foo").Id);
        }
Пример #10
0
        public void StopUsingMockAdapterStopsUsingMockAdapter()
        {
            var mock = new InMemoryAdapter();

            Database.UseMockAdapter(mock);
            Database db = Database.OpenNamedConnection("Mock");

            Assert.AreSame(mock, db.GetAdapter());
            Database.StopUsingMockAdapter();
            db = Database.OpenNamedConnection("Mock");
            Assert.IsInstanceOf <AdoAdapter>(db.GetAdapter());
        }
Пример #11
0
        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");
        }
Пример #12
0
 public void InsertAndGetShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Test.Insert(Id: 1, Name: "Alice");
     var record = db.Test.Get(1);
     Assert.IsNotNull(record);
     Assert.AreEqual(1, record.Id);
     Assert.AreEqual("Alice", record.Name);
 }
Пример #13
0
        public void InsertAndFindByTableNameResolvesCorrectlyWithHomogenisedStringComparer()
        {
            var inMemoryAdapter = new InMemoryAdapter(new AdoCompatibleComparer());

            Database.UseMockAdapter(inMemoryAdapter);
            var db = Database.Open();

            db.CUSTOMER.Insert(ID: 1, NAME: "ACME");

            var actual = db.Customers.FindById(1);
            Assert.IsNotNull(actual);
            Assert.AreEqual("ACME", actual.Name);
        }
Пример #14
0
        public void InsertAndFindByTableNameResolvesCorrectlyWithHomogenisedStringComparer()
        {
            var inMemoryAdapter = new InMemoryAdapter(new AdoCompatibleComparer());

            Database.UseMockAdapter(inMemoryAdapter);
            var db = Database.Open();

            db.CUSTOMER.Insert(ID: 1, NAME: "ACME");

            var actual = db.Customers.FindById(1);

            Assert.IsNotNull(actual);
            Assert.AreEqual("ACME", actual.Name);
        }
Пример #15
0
 public void InsertAndGetWithArrayPropertyShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Test.Insert(Id: 1, Names: new List<string> {"Alice", "Bob", "Charlie"});
     People record = db.Test.Get(1);
     Assert.IsNotNull(record);
     Assert.AreEqual(1, record.Id);
     Assert.AreEqual("Alice", record.Names[0]);
     Assert.AreEqual("Bob", record.Names[1]);
     Assert.AreEqual("Charlie", record.Names[2]);
 }
Пример #16
0
        public void UpsertShouldAddNewRecord()
        {
            var adapter = new InMemoryAdapter();

            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Test.Upsert(Id: 1, SomeValue: "Testing");
            var record = db.Test.Get(1);

            Assert.IsNotNull(record);
            Assert.AreEqual("Testing", record.SomeValue);
        }
Пример #17
0
        public void ShouldBeAbleToSetAutoIncrementWhenSettingKeyColumn()
        {
            // Arrange
            var adapter = new InMemoryAdapter();

            // Act
            adapter.SetAutoIncrementKeyColumn("Users", "Id");

            // Assert
            Database.UseMockAdapter(adapter);
            var db      = Database.Open();
            var firstId = db.Users.Insert(Name: "Marcus").Id;

            Assert.AreEqual(1, firstId);
        }
Пример #18
0
        public dynamic Db()
        {
            var inMemoryAdapter = new InMemoryAdapter();

            inMemoryAdapter.SetKeyColumn("LocalFeedInfo", "Id");

            Database.UseMockAdapter(inMemoryAdapter);

            if (_db == null)
            {
                _db = Database.Open();
            }

            return(_db);
        }
Пример #19
0
        public void InsertAndGetShouldWork()
        {
            var adapter = new InMemoryAdapter();

            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Test.Insert(Id: 1, Name: "Alice");
            var record = db.Test.Get(1);

            Assert.IsNotNull(record);
            Assert.AreEqual(1, record.Id);
            Assert.AreEqual("Alice", record.Name);
        }
Пример #20
0
        public void ProcedureReturningArrayShouldWork()
        {
            var adapter = new InMemoryAdapter();

            adapter.AddFunction("Test", () => new[] { new Dictionary <string, object> {
                                                          { "Foo", "Bar" }
                                                      } });
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            foreach (var row in db.Test())
            {
                Assert.AreEqual("Bar", row.Foo);
            }
        }
Пример #21
0
        public void ProcedureWithParametersReturningArrayShouldWork()
        {
            var adapter = new InMemoryAdapter();

            adapter.AddFunction <string, object, IDictionary <string, object>[]>("Test", (key, value) => new IDictionary <string, object>[] { new Dictionary <string, object> {
                                                                                                                                                  { key, value }
                                                                                                                                              } });
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            foreach (var row in db.Test("Foo", "Bar"))
            {
                Assert.AreEqual("Bar", row.Foo);
            }
        }
Пример #22
0
        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);
        }
Пример #23
0
        public void UpsertShouldUpdateExistingRecord()
        {
            var adapater = new InMemoryAdapter();

            adapater.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapater);
            var db = Database.Open();

            db.Test.Upsert(Id: 1, SomeValue: "Testing");
            db.Test.Upsert(Id: 1, SomeValue: "Updated");
            List <dynamic> allRecords = db.Test.All().ToList();

            Assert.IsNotNull(allRecords);
            Assert.AreEqual(1, allRecords.Count);
            Assert.AreEqual("Updated", allRecords.Single().SomeValue);
        }
Пример #24
0
        public void AutoIncrementShouldSet1ForAutoIncrementedColumnsWhenNoRowsInTable()
        {
            // Arrange
            var adapter = new InMemoryAdapter();

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

            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            // Act
            var newId = db.Users.Insert(Name: "Marcus").Id;

            // Assert
            Assert.AreEqual(1, newId);
        }
Пример #25
0
        public void TestUpdate()
        {
            var adapter = new InMemoryAdapter();

            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);
            var db      = Database.Open();
            var alice   = db.Test.Insert(Id: 1, Name: "Alice");
            var allyce  = new { Id = 1, Name = "Allyce" };
            int updated = db.Test.Update(allyce);

            Assert.AreEqual(1, updated);
            var record = db.Test.FindById(1);

            Assert.AreEqual("Allyce", record.Name);
        }
Пример #26
0
        public void UpdateWithOriginalValuesRowsUpdatedShouldBeZeroIfNewValueAreSameAsOriginalValue()
        {
            var adapter = new InMemoryAdapter();

            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Test.Upsert(Id: 1, SomeValue: "Testing");
            var record  = db.Test.Get(1);
            var record1 = record.Clone();

            var rowsUpdated = db.Test.Update(record, record1);

            Assert.AreEqual(0, rowsUpdated);
        }
Пример #27
0
        public void InsertAndGetWithTransactionShouldWork()
        {
            var adapter = new InMemoryAdapter();

            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            using (var tx = db.BeginTransaction())
            {
                tx.Test.Insert(Id: 1, Name: "Alice");
                var record = tx.Test.Get(1);
                Assert.IsNotNull(record);
                Assert.AreEqual(1, record.Id);
                Assert.AreEqual("Alice", record.Name);
            }
        }
Пример #28
0
        public void CanSimulateProcedureWithOutputParameters()
        {
            const string key     = "outparam";
            const string value   = "outParamValue";
            var          adapter = new InMemoryAdapter();

            adapter.AddFunction("Test", p =>
            {
                p.Add(key, value);
                return(p);
            });
            Database.UseMockAdapter(adapter);
            var db     = Database.Open();
            var result = db.Test();

            Assert.That(result.OutputValues[key], Is.EqualTo(value));
        }
Пример #29
0
        public void FindAllWhenUsingAnyOldPropertyNameShouldWork()
        {
            var adapter = new InMemoryAdapter();

            adapter.ConfigureJoin("Users", "Id", "Categories", "Categories", "UserId", "User");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Users.Insert(Id: 1, UserName: "******");
            db.Users.Insert(Id: 2, UserName: "******");
            db.Categories.Insert(Id: 1, UserId: 1, CategoryName: "Category 1");
            db.Categories.Insert(Id: 2, UserId: 2, CategoryName: "Category 2");

            var categories = db.Users.FindAll(db.User.Categories.CategoryName == "Category 1").ToList();

            Assert.NotNull(categories);
            Assert.AreEqual(1, categories.Count);
        }
Пример #30
0
        public void TestJoin()
        {
            var adapter = new InMemoryAdapter();

            adapter.ConfigureJoin("Customer", "ID", "Orders", "Order", "CustomerID", "Customer");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Customer.Insert(ID: 1, Name: "NASA");
            db.Customer.Insert(ID: 2, Name: "ACME");
            db.Order.Insert(ID: 1, CustomerID: 1, Date: new DateTime(1997, 1, 12));
            db.Order.Insert(ID: 2, CustomerID: 2, Date: new DateTime(2001, 1, 1));

            var customers = db.Customer.FindAll(db.Customer.Orders.Date < new DateTime(1999, 12, 31)).ToList();

            Assert.IsNotNull(customers);
            Assert.AreEqual(1, customers.Count);
        }
Пример #31
0
        public void AutoIncrementShouldReturnNextIdInSequenceWhenOneRowExsists()
        {
            // Arrange
            var adapter = new InMemoryAdapter();

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

            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Users.Insert(Name: "Marcus");

            // Act
            var newId = db.Users.Insert(Name: "Per").Id;

            // Assert
            Assert.AreEqual(2, newId);
        }
Пример #32
0
        public virtual void Init()
        {
            InMemoryAdapter.DisposeAll();

            IsRunningOnAzurePipelines = bool.Parse(TestContext.Properties["IsFromAzure"].ToString());

            var loggerFactory       = new LoggerFactory();
            var loggerConfiguration = new LoggerConfiguration();

            if (IsRunningOnAzurePipelines)
            {
                loggerConfiguration.MinimumLevel.Warning();
            }
            else
            {
                if (Debugger.IsAttached)
                {
                    loggerConfiguration.MinimumLevel.Information();
                }
                else
                {
                    loggerConfiguration.MinimumLevel.Information();
                }

                loggerConfiguration.WriteTo.Sink(new SerilogTestContextSink(TestContext));
                loggerConfiguration.WriteTo.Debug(Serilog.Events.LogEventLevel.Debug, "[{SourceContext}] [{Level}] [{Timestamp:HH:mm:ss.fff}]: {Message}{NewLine}{Exception}");
                loggerConfiguration.WriteTo.Seq("http://localhost:5341");
            }

            _logger = loggerConfiguration.CreateLogger();

            loggerFactory.AddSerilog(_logger);

            ResonanceGlobalSettings.Default.LoggerFactory = loggerFactory;

            StackTrace stackTrace = new StackTrace();
            var        testName   = stackTrace.GetFrame(1).GetMethod().Name;

            var logger = loggerFactory.CreateLogger(testName);

            logger.LogDebug("Starting Test...");

            Logger = logger;
        }
Пример #33
0
        public async Task <bool> SaveProduct(ProductViewModel product)
        {
            try
            {
                // TODO: Add insert logic here
                product.Product_obj.Id = Guid.NewGuid().ToString();

                if (VarsHelper.GetDataMode() == Enums.ModeType.SQLData)
                {
                    localdbRepository.Products.Add(product.Product_obj);

                    foreach (var item in product.CategoryId)
                    {
                        localdbRepository.Product_Category.Add(new Product_Category()
                        {
                            Id = Guid.NewGuid().ToString(), Category_Id = item, Product_Id = product.Product_obj.Id
                        });
                    }


                    await localdbRepository.SaveChangesAsync();
                }
                else
                {
                    List <Repository.Product> lst = new List <Repository.Product>();
                    lst = (List <Repository.Product>)InMemoryAdapter.Get(PRODUCTS);
                    if (lst == null)
                    {
                        lst = new List <Repository.Product>();
                    }

                    lst.Add(product.Product_obj);

                    InMemoryAdapter.Set <List <Repository.Product> >(PRODUCTS, lst);
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #34
0
        public static Container BootstrapContainerAndAdapters(Action <Container> registerOverrides = null)
        {
            var container = new Container();

            AuthorisationAdapter.Register(container, new FeatureToggles {
                UseConsoleAuthorisation = true
            });
            InMemoryAdapter.Register(container);

            if (registerOverrides != null)
            {
                container.Options.AllowOverridingRegistrations = true;
                registerOverrides(container);
            }

            container.Verify();

            return(container);
        }
Пример #35
0
 public void ProcedureWithParametersReturningArrayShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.AddFunction<string, object, IDictionary<string, object>[]>("Test", (key, value) => new IDictionary<string, object>[] {new Dictionary<string, object> { { key, value } }});
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     foreach (var row in db.Test("Foo", "Bar"))
     {
         Assert.AreEqual("Bar", row.Foo);
     }
 }
Пример #36
0
 public void UpsertShouldAddNewRecord()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Test.Upsert(Id: 1, SomeValue: "Testing");
     var record = db.Test.Get(1);
     Assert.IsNotNull(record);
     Assert.AreEqual("Testing", record.SomeValue);
 }
Пример #37
0
 public void InsertAndGetWithTransactionShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     using (var tx = db.BeginTransaction())
     {
         tx.Test.Insert(Id: 1, Name: "Alice");
         var record = tx.Test.Get(1);
         Assert.IsNotNull(record);
         Assert.AreEqual(1, record.Id);
         Assert.AreEqual("Alice", record.Name);
     }
 }
Пример #38
0
 public void ProcedureReturningArrayShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.AddFunction("Test", () => new[] { new Dictionary<string, object> { { "Foo", "Bar" } } });
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     foreach (var row in db.Test())
     {
         Assert.AreEqual("Bar", row.Foo);
     }
 }
Пример #39
0
 public void CanSimulateProcedureWithOutputParameters()
 {
     const string key = "outparam";
     const string value = "outParamValue";
     var adapter = new InMemoryAdapter();
     adapter.AddFunction("Test", p =>
         {
             p.Add(key, value);
             return p;
         });
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     var result = db.Test();
     Assert.That(result.OutputValues[key], Is.EqualTo(value));
 }
Пример #40
0
        public void TestJoinWithAlias()
        {
            var adapter = new InMemoryAdapter();
            adapter.ConfigureJoin("Customer", "ID", "Customer", "Orders", "CustomerID", "Orders");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Customer.Insert(ID: 1, Name: "NASA");
            db.Customer.Insert(ID: 2, Name: "ACME");
            db.Orders.Insert(ID: 1, Name: "Order1", CustomerID: 1);
            db.Orders.Insert(ID: 2, Name: "Order2", CustomerID: 2);
            db.Orders.Insert(ID: 3, Name: "Order3", CustomerID: 2);

            IEnumerable<dynamic> orders = db.Orders.Query()
                .Where(db.Orders.Customer.Name == "ACME")
                .Select(db.Orders.Name.As("OrderName"),
                        db.Orders.Customer.Name.As("CustomerName"))
                .ToList();
            Assert.IsNotNull(orders);
            Assert.AreEqual(2, orders.Count());
            Assert.AreEqual(2, orders.Count(x => x.CustomerName == "ACME"));
        }
Пример #41
0
        public void AutoIncrementShouldReturnNextIdInSequenceWhenOneRowExsists()
        {
            // Arrange
            var adapter = new InMemoryAdapter();
            adapter.SetAutoIncrementColumn("Users", "Id");

            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Users.Insert(Name: "Marcus");

            // Act
            var newId = db.Users.Insert(Name: "Per").Id;

            // Assert
            Assert.AreEqual(2, newId);
        }
Пример #42
0
 public void JoinTest()
 {
     Guid masterId = Guid.NewGuid();
     InMemoryAdapter adapter = new InMemoryAdapter();
     adapter.Join.Master("Master", "Id").Detail("Detail", "MasterId");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Master.Insert(Id: masterId);
     db.Detail.Insert(Id: Guid.NewGuid(), MasterId: masterId, Box: 999);
     // Act
     IEnumerable<dynamic> list = db.Detail.All()
         .Join(db.Master).On(db.Master.Id == db.Detail.MasterId)
         .Select(db.Master.Id, db.Detail.Box)
                 .Cast<dynamic>();
     // Assert
     dynamic detail = list.FirstOrDefault();
     Assert.NotNull(detail);
     Assert.That(detail.Id, Is.EqualTo(masterId));
     Assert.That(detail.Box, Is.EqualTo(999));
 }
Пример #43
0
        public void FindAllWhenUsingAnyOldPropertyNameShouldWork()
        {
            var adapter = new InMemoryAdapter();
            adapter.ConfigureJoin("Users", "Id", "User", "Categories", "UserId", "Categories");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Users.Insert(Id: 1, UserName: "******");
            db.Users.Insert(Id: 2, UserName: "******");
            db.Categories.Insert(Id: 1, UserId: 1, CategoryName: "Category 1");
            db.Categories.Insert(Id: 2, UserId: 2, CategoryName: "Category 2");

            var categories = db.Users.FindAll(db.User.Categories.CategoryName == "Category 1").ToList();
            Assert.NotNull(categories);
            Assert.AreEqual(1, categories.Count);
        }
Пример #44
0
        public void AutoIncrementShouldSet1ForAutoIncrementedColumnsWhenNoRowsInTable()
        {
            // Arrange
            var adapter = new InMemoryAdapter();
            adapter.SetAutoIncrementColumn("Users", "Id");

            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            // Act
            var newId = db.Users.Insert(Name: "Marcus").Id;

            // Assert
            Assert.AreEqual(1, newId);
        }
Пример #45
0
        public void TestJoinConfig()
        {
            var adapter = new InMemoryAdapter();
            adapter.Join.Master("Customer", "ID").Detail("Order", "CustomerID");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Customer.Insert(ID: 1, Name: "NASA");
            db.Customer.Insert(ID: 2, Name: "ACME");
            db.Order.Insert(ID: 1, CustomerID: 1, Date: new DateTime(1997, 1, 12));
            db.Order.Insert(ID: 2, CustomerID: 2, Date: new DateTime(2001, 1, 1));

            var customers = db.Customer.FindAll(db.Customer.Order.Date < new DateTime(1999, 12, 31)).ToList();
            Assert.IsNotNull(customers);
            Assert.AreEqual(1, customers.Count);
        }
Пример #46
0
 public void TestUpdate()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     var alice = db.Test.Insert(Id: 1, Name: "Alice");
     var allyce = new { Id = 1, Name = "Allyce" };
     int updated = db.Test.Update(allyce);
     Assert.AreEqual(1, updated);
     var record = db.Test.FindById(1);
     Assert.AreEqual("Allyce", record.Name);
 }
Пример #47
0
        public void TestFindAcrossJoinAfterDelete()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Thing1Table", "Id");
            adapter.SetKeyColumn("Thing2Table", "Id");
            adapter.Join.Master("Thing1Table", "Id").Detail("ThingJoin", "Thing1Id");
            adapter.Join.Master("Thing2Table", "Id").Detail("ThingJoin", "Thing2Id");

            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            var thing1 = new {Id = 1, Name = "Thing1"};
            var thing2 = new {Id = 2, Name = "Thing2"};
            var thingJoin = new {Thing1Id = 1, Thing2Id = 2};
 
            db.Thing1Table.Insert(thing1);
            db.Thing2Table.Insert(thing2);
            db.ThingJoin.Insert(thingJoin);
 
            //Delete the join object.
            db.ThingJoin.DeleteAll(db.ThingJoin.Thing1Id == 1 && db.ThingJoin.Thing2Id == 2);
            
            //Ensure after we drop one of the relationships, there is only no records left in the join table.
            Assert.AreEqual(0, db.ThingJoin.All().ToList().Count);

            //Ensure we don't find the Thing across the join after the delete
            var foundByJoin = db.Thing1Table.FindAll(db.Thing1Table.ThingJoin.Thing1Id == 1).FirstOrDefault();
            Assert.IsNull(foundByJoin);
        }
Пример #48
0
 public void UpsertShouldUpdateExistingRecord()
 {
     var adapater = new InMemoryAdapter();
     adapater.SetKeyColumn("Test","Id");
     Database.UseMockAdapter(adapater);
     var db = Database.Open();
     db.Test.Upsert(Id: 1, SomeValue: "Testing");
     db.Test.Upsert(Id: 1, SomeValue: "Updated");
     List<dynamic> allRecords = db.Test.All().ToList();
     Assert.IsNotNull(allRecords);
     Assert.AreEqual(1,allRecords.Count);
     Assert.AreEqual("Updated", allRecords.Single().SomeValue);
 }
Пример #49
0
        public void ShouldBeAbleToSetAutoIncrementWhenSettingKeyColumn()
        {
            // Arrange
            var adapter = new InMemoryAdapter();

            // Act
            adapter.SetAutoIncrementKeyColumn("Users", "Id");

            // Assert
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            var firstId = db.Users.Insert(Name: "Marcus").Id;
            Assert.AreEqual(1, firstId);
        }
Пример #50
0
 public void UpsertWithoutDefinedKeyColumnsSHouldThrowMeaningfulException()
 {
     var adapter = new InMemoryAdapter();
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     var exception = Assert.Throws<InvalidOperationException>(() => db.Test.Upsert(Id: 1, HasTowel: true));
     Assert.AreEqual("No key columns defined for table \"Test\"", exception.Message);
 }
Пример #51
0
 private static int ThreadTestHelper(int userId)
 {
     var mockAdapter = new InMemoryAdapter();
     Database.UseMockAdapter(mockAdapter);
     var db = Database.Open();
     db.Users.Insert(Id: userId, Email: "foo");
     return Database.Default.Users.FindByEmail("foo").Id;
 }
Пример #52
0
        public void LeftJoinTest()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Events", "Id");
            adapter.SetAutoIncrementColumn("Events", "Id");
            adapter.SetKeyColumn("Doors", "Id");
            adapter.SetAutoIncrementColumn("Doors", "Id");
            adapter.Join.Master("Events", "Id").Detail("Doors", "EventId");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Events.Insert(Id: 1, Code: "CodeMash2013", Name: "CodeMash 2013");
            db.Events.Insert(Id: 2, Code: "SomewhereElse", Name: "Some Other Conf");
            db.Doors.Insert(Id: 1, Code: "F7E08AC9-5E75-417D-A7AA-60E88B5B99AD", EventID: 1);
            db.Doors.Insert(Id: 2, Code: "0631C802-2748-4C63-A6D9-CE8C803002EB", EventID: 1);
            db.Doors.Insert(Id: 3, Code: "281ED88F-677D-49B9-84FA-4FAE022BBC73", EventID: 1);
            db.Doors.Insert(Id: 4, Code: "9DF7E964-1ECE-42E3-8211-1F2BF7054A0D", EventID: 2);
            db.Doors.Insert(Id: 5, Code: "9418123D-312A-4E8C-8807-59F0A63F43B9", EventID: 2);

            List<dynamic> actual = db.Doors.FindAll(db.Doors.Events.Code == "CodeMash2013")
                           .Select(db.Doors.Id, db.Events.Name)
                           .ToList();

            Assert.AreEqual(3, actual.Count);
        }
Пример #53
0
        public void UpdateWithOriginalValuesRowsUpdatedShouldBeZeroIfNewValueAreSameAsOriginalValue()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Test.Upsert(Id: 1, SomeValue: "Testing");
            var record = db.Test.Get(1);
            var record1 = record.Clone();

            var rowsUpdated = db.Test.Update(record, record1);

            Assert.AreEqual(0, rowsUpdated);
        }