public void Can_Instantiate_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            // Act
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Assert
                Assert.That(repository, Is.Not.Null);    
            }
        }
Esempio n. 2
0
        public void Can_Instantiate_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            // Act
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Assert
                Assert.That(repository, Is.Not.Null);
            }
        }
        public void Can_Instantiate_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                // Assert
                Assert.That(repository, Is.Not.Null);
            }
        }
        public void Cannot_Add_Duplicate_Server_Identities()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                var server = new ServerRegistration("http://shazwazza.com", "COMPUTER1", DateTime.Now);

                Assert.That(() => repository.Save(server), Throws.InstanceOf <DbException>());
            }
        }
        public void Cannot_Update_To_Duplicate_Server_Identities()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                IServerRegistration server = repository.Get(1);
                server.ServerIdentity = "COMPUTER2";

                Assert.That(() => repository.Save(server), Throws.InstanceOf <DbException>());
            }
        }
Esempio n. 6
0
        public void Cannot_Add_Duplicate_Computer_Names()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            // Act
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                var server = new ServerRegistration("http://shazwazza.com", "COMPUTER1", DateTime.Now);
                repository.AddOrUpdate(server);

                Assert.Throws <SqlCeException>(unitOfWork.Commit);
            }
        }
Esempio n. 7
0
        public void Cannot_Update_To_Duplicate_Computer_Names()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            // Act
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                var server = repository.Get(1);
                server.ComputerName = "COMPUTER2";
                repository.AddOrUpdate(server);
                Assert.Throws <SqlCeException>(unitOfWork.Commit);
            }
        }
Esempio n. 8
0
        public void Can_Perform_GetAll_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var servers = repository.GetAll();

                // Assert
                Assert.That(servers.Count(), Is.EqualTo(3));
            }
        }
        public void Cannot_Add_Duplicate_Computer_Names()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            // Act
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                var server = new ServerRegistration("http://shazwazza.com", "COMPUTER1", DateTime.Now);
                repository.AddOrUpdate(server);

                Assert.Throws<SqlCeException>(unitOfWork.Commit);
            }

        }
Esempio n. 10
0
        public void CreateTestData()
        {
            var provider = new PetaPocoUnitOfWorkProvider();

            using (var unitOfWork = provider.GetUnitOfWork())
                using (var repository = new ServerRegistrationRepository(unitOfWork))
                {
                    repository.AddOrUpdate(new ServerRegistration("http://localhost", "COMPUTER1", DateTime.Now)
                    {
                        IsActive = true
                    });
                    repository.AddOrUpdate(new ServerRegistration("http://www.mydomain.com", "COMPUTER2", DateTime.Now));
                    repository.AddOrUpdate(new ServerRegistration("https://www.another.domain.com", "Computer3", DateTime.Now));
                    unitOfWork.Commit();
                }
        }
        public void Cannot_Update_To_Duplicate_Computer_Names()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            // Act
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                var server = repository.Get(1);
                server.ComputerName = "COMPUTER2";
                repository.AddOrUpdate(server);
                Assert.Throws<SqlCeException>(unitOfWork.Commit);
            }

        }
        public void Can_Perform_GetAll_On_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                // Act
                IEnumerable <IServerRegistration> servers = repository.GetMany();

                // Assert
                Assert.That(servers.Count(), Is.EqualTo(3));
            }
        }
        public void CreateTestData()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                repository.Save(new ServerRegistration("http://localhost", "COMPUTER1", DateTime.Now)
                {
                    IsActive = true
                });
                repository.Save(new ServerRegistration("http://www.mydomain.com", "COMPUTER2", DateTime.Now));
                repository.Save(new ServerRegistration("https://www.another.domain.com", "Computer3", DateTime.Now));
                scope.Complete();
            }
        }
Esempio n. 14
0
        public void Can_Perform_GetByQuery_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var query = Query <ServerRegistration> .Builder.Where(x => x.ComputerName.ToUpper() == "COMPUTER3");

                var result = repository.GetByQuery(query);

                // Assert
                Assert.AreEqual(1, result.Count());
            }
        }
Esempio n. 15
0
        public void Can_Perform_Count_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var query = Query <ServerRegistration> .Builder.Where(x => x.ServerAddress.StartsWith("http://"));

                int count = repository.Count(query);

                // Assert
                Assert.That(count, Is.EqualTo(2));
            }
        }
Esempio n. 16
0
        public void Can_Perform_Exists_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var exists      = repository.Exists(3);
                var doesntExist = repository.Exists(10);

                // Assert
                Assert.That(exists, Is.True);
                Assert.That(doesntExist, Is.False);
            }
        }
Esempio n. 17
0
        public void Can_Perform_Get_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = repository.Get(1);

                // Assert
                Assert.That(server, Is.Not.Null);
                Assert.That(server.HasIdentity, Is.True);
                Assert.That(server.ServerAddress, Is.EqualTo("http://localhost"));
            }
        }
        public void Can_Perform_Add_On_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                // Act
                var server = new ServerRegistration("http://shazwazza.com", "COMPUTER4", DateTime.Now);
                repository.Save(server);

                // Assert
                Assert.That(server.HasIdentity, Is.True);
                Assert.That(server.Id, Is.EqualTo(4)); // With 3 existing entries the Id should be 4
            }
        }
        public void Can_Perform_Get_On_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                // Act
                IServerRegistration server = repository.Get(1);

                // Assert
                Assert.That(server, Is.Not.Null);
                Assert.That(server.HasIdentity, Is.True);
                Assert.That(server.ServerAddress, Is.EqualTo("http://localhost"));
            }
        }
Esempio n. 20
0
        public void Can_Perform_Add_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = new ServerRegistration("http://shazwazza.com", "COMPUTER4", DateTime.Now);
                repository.AddOrUpdate(server);
                unitOfWork.Commit();

                // Assert
                Assert.That(server.HasIdentity, Is.True);
                Assert.That(server.Id, Is.EqualTo(4));//With 3 existing entries the Id should be 4
            }
        }
        public void Can_Perform_Exists_On_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                // Act
                bool exists      = repository.Exists(3);
                bool doesntExist = repository.Exists(10);

                // Assert
                Assert.That(exists, Is.True);
                Assert.That(doesntExist, Is.False);
            }
        }
        public void Can_Perform_Get_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = repository.Get(1);

                // Assert
                Assert.That(server, Is.Not.Null);
                Assert.That(server.HasIdentity, Is.True);
                Assert.That(server.ServerAddress, Is.EqualTo("http://localhost"));    
            }

            
        }
        public void Can_Perform_Delete_On_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                // Act
                IServerRegistration server = repository.Get(3);
                Assert.IsNotNull(server);
                repository.Delete(server);

                bool exists = repository.Exists(3);

                // Assert
                Assert.That(exists, Is.False);
            }
        }
Esempio n. 24
0
        public void Can_Perform_Delete_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = repository.Get(3);
                Assert.IsNotNull(server);
                repository.Delete(server);
                unitOfWork.Commit();

                var exists = repository.Exists(3);

                // Assert
                Assert.That(exists, Is.False);
            }
        }
        public void Can_Perform_Update_On_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ServerRegistrationRepository repository = CreateRepository(provider);

                // Act
                IServerRegistration server = repository.Get(2);
                server.ServerAddress = "https://umbraco.com";
                server.IsActive      = true;

                repository.Save(server);

                IServerRegistration serverUpdated = repository.Get(2);

                // Assert
                Assert.That(serverUpdated, Is.Not.Null);
                Assert.That(serverUpdated.ServerAddress, Is.EqualTo("https://umbraco.com"));
                Assert.That(serverUpdated.IsActive, Is.EqualTo(true));
            }
        }
Esempio n. 26
0
        public void Can_Perform_Update_On_Repository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = repository.Get(2);
                server.ServerAddress = "https://umbraco.com";
                server.IsActive      = true;

                repository.AddOrUpdate(server);
                unitOfWork.Commit();

                var serverUpdated = repository.Get(2);

                // Assert
                Assert.That(serverUpdated, Is.Not.Null);
                Assert.That(serverUpdated.ServerAddress, Is.EqualTo("https://umbraco.com"));
                Assert.That(serverUpdated.IsActive, Is.EqualTo(true));
            }
        }
        public void Can_Perform_GetAll_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var servers = repository.GetAll();

                // Assert
                Assert.That(servers.Count(), Is.EqualTo(3));    
            }
            
        }
        public void Can_Perform_Count_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var query = Query<ServerRegistration>.Builder.Where(x => x.ServerAddress.StartsWith("http://"));
                int count = repository.Count(query);

                // Assert
                Assert.That(count, Is.EqualTo(2));    
            }
        }
        public void Can_Perform_Add_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = new ServerRegistration("http://shazwazza.com", "COMPUTER4", DateTime.Now);
                repository.AddOrUpdate(server);
                unitOfWork.Commit();

                // Assert
                Assert.That(server.HasIdentity, Is.True);
                Assert.That(server.Id, Is.EqualTo(4));//With 3 existing entries the Id should be 4   
            }            
        }
        public void Can_Perform_Update_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = repository.Get(2);
                server.ServerAddress = "https://umbraco.com";
                server.IsActive = true;

                repository.AddOrUpdate(server);
                unitOfWork.Commit();

                var serverUpdated = repository.Get(2);

                // Assert
                Assert.That(serverUpdated, Is.Not.Null);
                Assert.That(serverUpdated.ServerAddress, Is.EqualTo("https://umbraco.com"));
                Assert.That(serverUpdated.IsActive, Is.EqualTo(true));   
            }            
        }
        public void Can_Perform_Delete_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var server = repository.Get(3);
                Assert.IsNotNull(server);
                repository.Delete(server);
                unitOfWork.Commit();

                var exists = repository.Exists(3);

                // Assert
                Assert.That(exists, Is.False);   
            }            
        }
        public void Can_Perform_Exists_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var exists = repository.Exists(3);
                var doesntExist = repository.Exists(10);

                // Assert
                Assert.That(exists, Is.True);
                Assert.That(doesntExist, Is.False);    
            }
        }
        public void Can_Perform_GetByQuery_On_Repository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                // Act
                var query = Query<ServerRegistration>.Builder.Where(x => x.ComputerName.ToUpper() == "COMPUTER3");
                var result = repository.GetByQuery(query);

                // Assert
                Assert.AreEqual(1, result.Count());    
            }
        }
        public void CreateTestData()
        {
            var provider = new PetaPocoUnitOfWorkProvider();
            using (var unitOfWork = provider.GetUnitOfWork())
            using (var repository = new ServerRegistrationRepository(unitOfWork))
            {
                repository.AddOrUpdate(new ServerRegistration("http://localhost", "COMPUTER1", DateTime.Now) { IsActive = true });
                repository.AddOrUpdate(new ServerRegistration("http://www.mydomain.com", "COMPUTER2", DateTime.Now));
                repository.AddOrUpdate(new ServerRegistration("https://www.another.domain.com", "Computer3", DateTime.Now));
                unitOfWork.Commit();
            }

        }