示例#1
0
        public void NullObject()
        {
            NullRepository.RegisterValue(new Customer {
                Name = "Unknown"
            });

            Customer customer = new Customer {
                Name = "Brian"
            };
            Customer nullCustomer = null;

            Customer repositoryCustomer = NullRepository.Retrieve(customer);

            Assert.AreEqual(customer.Name, repositoryCustomer.Name);

            repositoryCustomer = NullRepository.Retrieve(nullCustomer);
            Assert.AreEqual("Unknown", repositoryCustomer.Name);
        }
示例#2
0
        public void Test2()
        {
            NullRepository.RegisterConversionValue <DateTime>(0000);
            NullRepository.RegisterConversionValue <DateTime>("Unknown");

            DateTime?hasValue = new DateTime(2001, 1, 1);
            DateTime?noValue  = null;

            string hasValueActual           = hasValue.ConvertOrDefault(x => x.ToString("MM/dd/yyyy"));
            string noValueConvertedToString = noValue.ConvertOrDefault(x => x.ToString("MM/dd/yyyy"));
            int    noValueConvertedToInt    = noValue.ConvertOrDefault(x => x.Year);

            string dateTimeDefault = NullRepository.RetrieveConversion <DateTime, string>();

            Assert.AreEqual("01/01/2001", hasValueActual);
            Assert.AreEqual(0000, noValueConvertedToInt);
            Assert.AreEqual("Unknown", noValueConvertedToString);
            Assert.AreEqual("Unknown", dateTimeDefault);
        }
示例#3
0
        public void NullRepositoryCommitTests()
        {
            // arrange
            var settings     = MockSettings();
            var environment  = MockEnviroment(@"x:\site", settings.Object);
            var traceFactory = MockTraceFactory();
            var httpContext  = MockHttpContext();

            // test
            var repository = new NullRepository(environment.Object, traceFactory.Object, httpContext.Object);

            // Assert
            Assert.Equal(RepositoryType.None, repository.RepositoryType);
            Assert.Equal(environment.Object.RepositoryPath, repository.RepositoryPath);
            Assert.Null(repository.CurrentId);
            Assert.Throws <InvalidOperationException>(() => repository.GetChangeSet("dummy"));
            Assert.Throws <InvalidOperationException>(() => repository.GetChangeSet("master"));

            // Simple commit
            var message = "this is testing";
            var author  = "john doe";
            var email   = "*****@*****.**";
            var success = repository.Commit(message, author, email);

            // Assert
            Assert.True(success);
            Assert.NotNull(repository.CurrentId);

            // Validate changeset
            var changeSet = repository.GetChangeSet(repository.CurrentId);

            // Assert
            Assert.NotNull(changeSet);
            Assert.Equal(message, changeSet.Message);
            Assert.Equal(author, changeSet.AuthorName);
            Assert.Equal(email, changeSet.AuthorEmail);
            Assert.True(changeSet.IsReadOnly);
            Assert.Equal(repository.CurrentId, changeSet.Id);
            Assert.Throws <InvalidOperationException>(() => repository.GetChangeSet("dummy"));
            Assert.Same(changeSet, repository.GetChangeSet("master"));
            Assert.Same(changeSet, repository.GetChangeSet(repository.CurrentId));
        }