Ejemplo n.º 1
0
            public void ShouldEqualInsertedCount()
            {
                //Arrange
                var connectionString = DataModelHelpers.GetRandomConnectionString();
                var dbContext = new Context(connectionString);

                try
                {
                    Helpers.SetInitializer(new ContextInitializer(SeedContext));
                    using (var repository = new GenericDbRepository<Home, DataModel.Home>(_mapper, dbContext))
                    {
                        // Act
                        var data = repository.All();

                        // Assert
                        Assert.IsTrue(data.Any());
                    }
                }
                catch { throw; }
                finally { dbContext.Database.Delete(); }
            }
Ejemplo n.º 2
0
            public void ShouldRespectSorter()
            {
                //Arrange
                var connectionString = DataModelHelpers.GetRandomConnectionString();
                var dbContext = new Context(connectionString);

                try
                {
                    Helpers.SetInitializer(new ContextInitializer(SeedContext));
                    using (var repository = new GenericDbRepository<Home, DataModel.Home>(_mapper, dbContext))
                    {
                        // Act
                        var data = repository.All(sorters: new SortHomes(SortOrder.ASC, dateBuilt: true)).ToList();

                        // Assert
                        Assert.IsTrue(data.Any());
                        Assert.AreEqual(new DateTime(1982, 5, 1), data.First().DateBuilt);
                    }
                }
                catch { throw; }
                finally { dbContext.Database.Delete(); }
            }
Ejemplo n.º 3
0
            public void ShouldEqualInsertedCount()
            {
                var connectionString = DataModelHelpers.GetRandomConnectionString();
                var dbContext = new Context(connectionString);

                try
                {
                    Helpers.SetInitializer(new ContextInitializer(context =>
                    {
                        using (var repository = new GenericDbRepository<Home, DataModel.Home>(_mapper, dbContext))
                        {
                            repository.Merge(new Home
                            {
                                Id = Guid.NewGuid(),
                                Address = ""
                            });
                            repository.Merge(new Home
                            {
                                Id = Guid.NewGuid(),
                                Address = ""
                            });
                        }
                    }));

                    using (var repository = new GenericDbRepository<Home, DataModel.Home>(_mapper, dbContext))
                    {
                        var expected = 2;

                        int? actual = 0;
                        repository.All(ref actual, pageSize: 1, pageIndex: 0);
                        Assert.AreEqual(expected, actual);

                        actual = repository.Count();
                        Assert.AreEqual(expected, actual);
                    }
                }
                catch { throw; }
                finally { dbContext.Database.Delete(); }
            }
Ejemplo n.º 4
0
            public void ShouldRespectFilter()
            {
                //Arrange
                var connectionString = DataModelHelpers.GetRandomConnectionString();
                var dbContext = new Context(connectionString);

                try
                {
                    Helpers.SetInitializer(new ContextInitializer(SeedContext));
                    using (var repository = new GenericDbRepository<Home, DataModel.Home>(_mapper, dbContext))
                    {
                        // Act
                        var data = repository.All(new FilterHomes(roomNames: new[]{"Dining Room"})).ToList();

                        // Assert
                        Assert.IsTrue(data.Any());
                        Assert.AreEqual(2, data.Count());
                    }
                }
                catch { throw; }
                finally { dbContext.Database.Delete(); }
            }