public void Base_Inheritance_Save()
 {
     var repository = new UserRepository();
     var user = new User {Name = "Base_Inheritance_Save"};
     repository.Add(user);
     repository._collectionName.Should().Be("User");
 }
Exemplo n.º 2
0
        public void Get_WhenObjectId_IsObjectId_ReturnsUser()
        {
            //arrange
            var mongoRepository = new MongoRepository<User>();
            var user = new User() { Name = "Get_WhenObjectId_IsObjectId_ReturnsUser" };
            user = mongoRepository.Add(user);

            //act
            var found = mongoRepository.Get(user.Id);

            //assert
            found.Should().NotBeNull();
            found.Name.Should().Be(user.Name);
            found.Id.Should().Be(user.Id);
        }
        public void test_child_collection_match_using_any()
        {
            var mongoRepository = new MongoRepository<User>(collection: "UserCollection");
            mongoRepository.RemoveAll();
            mongoRepository.Linq().ToList().Should().BeEmpty();

            var user = new User()
            {
                Name = "1",
                Accounts = new List<Account>()
                {
                    new Account()
                    {
                        Name = "a1",
                        Prop2 = "p1"
                    }
                }
            };

            var user2 = new User()
            {
                Name = "2",
                Accounts = new List<Account>()
                {
                    new Account()
                    {
                        Name = "a2",
                        Prop2 = "p2"
                    }
                }
            };

            mongoRepository.Add(user);
            mongoRepository.Add(user2);
            mongoRepository.Linq().ToList().Should().HaveCount(2);

            var match =
                mongoRepository.Linq().SingleOrDefault(x => x.Accounts.Any(a => a.Name == "a1" && a.Prop2 == "p1"));
            match.Should().NotBeNull();
        }
Exemplo n.º 4
0
 public void Basic_Save()
 {
     var mongoRepository = new MongoRepository<User>();
     var user = new User() {Name = "Basic_Save"};
     mongoRepository.Add(user);
 }