Пример #1
0
        public void CanListEntitiesByNameOrSurname()
        {
            // Arrange
            var conn = GetConnectionString();

            var repo         = new SqliteUserRepository(conn);
            var entity1      = new User(0, "email1", new byte[] { 0x1, 0x1 }, "NameB", "Surname1", false, false);
            var entity2      = new User(0, "email2", new byte[] { 0x2, 0x2 }, "Name2", "SurnameA", true, true);
            var entity3      = new User(0, "email2", new byte[] { 0x2, 0x2 }, "Name3", "SurnameB", true, true);
            var savedEntity1 = repo.AddOrUpdate(entity1);

            repo.AddOrUpdate(entity2);
            var savedEntity3 = repo.AddOrUpdate(entity3);
            var filters      = ImmutableList.Create(new[]
Пример #2
0
        public void CanListEntitiesByIdAndNameNotFound()
        {
            // Arrange
            var conn = GetConnectionString();

            var repo    = new SqliteUserRepository(conn);
            var entity1 = new User(0, "email1", new byte[] { 0x1, 0x1 }, "Name1", "Surname1", false, false);
            var entity2 = new User(0, "email2", new byte[] { 0x2, 0x2 }, "Name2", "Surname2", true, true);

            repo.AddOrUpdate(entity1);
            repo.AddOrUpdate(entity2);
            var filters = ImmutableList.Create(new[] { new Filter <User>("Id", (uint)1), new Filter <User>("Name", "Name2") });

            // Act
            var listEntities = repo.ListEntities(filters);

            // Assert
            Assert.IsTrue(listEntities.IsValid);
            Assert.IsFalse(listEntities.Value.Any());
        }
Пример #3
0
        public void CanListEntitiesActive()
        {
            // Arrange
            var conn = GetConnectionString();

            var repo         = new SqliteUserRepository(conn);
            var entity1      = new User(0, "email1", new byte[] { 0x1, 0x2 }, "Name1", isActive: true);
            var savedEntity1 = repo.AddOrUpdate(entity1);
            var entity2      = new User(0, "email2", new byte[] { 0x2, 0x1 }, "Name2", isActive: false);

            _ = repo.AddOrUpdate(entity2);

            // Act
            var listEntities = repo.ListEntities(status: Status.Active);

            // Assert
            Assert.IsTrue(listEntities.IsValid);
            Assert.IsTrue(listEntities.Value.Count == 1);
            Assert.IsTrue(savedEntity1.Value.Equals(listEntities.Value.First()));
        }
Пример #4
0
        public void CanListEntitiesByEmail()
        {
            // Arrange
            var conn = GetConnectionString();

            var repo    = new SqliteUserRepository(conn);
            var entity1 = new User(0, "email1", new byte[] { 0x1, 0x1 }, "Name1", "Surname1", false, false);
            var entity2 = new User(0, "email2", new byte[] { 0x2, 0x2 }, "Name2", "Surname2", true, true);

            repo.AddOrUpdate(entity1);
            var savedEntity2 = repo.AddOrUpdate(entity2);
            var filters      = ImmutableList.Create(new Filter <User>("Email", "email2"));

            // Act
            var listEntities = repo.ListEntities(filters);

            // Assert
            Assert.IsTrue(listEntities.IsValid);
            Assert.IsTrue(listEntities.Value.Any());
            Assert.IsTrue(savedEntity2.Value.Equals(listEntities.Value.First()));
        }
Пример #5
0
        public void AddOrUpdateEntityIsRequired()
        {
            // Arrange
            var conn = GetConnectionString();
            var repo = new SqliteUserRepository(conn);

            // Act
            var result = repo.AddOrUpdate(null);

            // Assert
            Assert.IsFalse(result.IsValid);
            Assert.IsTrue(result.Exception is ArgumentNullException);
        }
Пример #6
0
        public void AddOrUpdateIsSafe()
        {
            // Arrange
            var conn   = GetConnectionString();
            var entity = new User(0, "email", new byte[] { 0x1, 0x2 }, "Name", "Surname");
            var repo   = new SqliteUserRepository(conn);

            // Act
            _conn.Dispose();
            var newEntity = repo.AddOrUpdate(entity);

            // Assert
            Assert.IsFalse(newEntity.IsValid);
        }
Пример #7
0
        public void CanGetEntityById()
        {
            // Arrange
            var conn        = GetConnectionString();
            var repo        = new SqliteUserRepository(conn);
            var entity      = new User(0, "email", new byte[] { 0x1, 0x2 }, "Name");
            var savedEntity = repo.AddOrUpdate(entity);

            // Act
            var result = repo.GetById(savedEntity.Value.Id);

            // Assert
            Assert.IsTrue(result.IsValid);
            Assert.IsTrue(result.Value.Equals(savedEntity.Value));
        }
Пример #8
0
        public void CanCreateEntity()
        {
            // Arrange
            var conn = GetConnectionString();

            var repo   = new SqliteUserRepository(conn);
            var entity = new User(0, "email", new byte[] { 0x1, 0x2 }, "Name");

            // Act
            var newEntity = repo.AddOrUpdate(entity);

            // Assert
            Assert.IsTrue(newEntity.IsValid);
            Assert.IsTrue(newEntity.Value.Id == 1);
        }
Пример #9
0
        public void CanListEntities()
        {
            // Arrange
            var conn = GetConnectionString();

            var repo        = new SqliteUserRepository(conn);
            var entity      = new User(0, "email", new byte[] { 0x1, 0x2 }, "Name");
            var savedEntity = repo.AddOrUpdate(entity);

            // Act
            var listEntities = repo.ListEntities();

            // Assert
            Assert.IsTrue(listEntities.IsValid);
            Assert.IsTrue(listEntities.Value.Any());
            Assert.IsTrue(savedEntity.Value.Equals(listEntities.Value.First()));
        }