示例#1
0
        public void Get_List_WithSqlCompact()
        {
            // Arrange
            var data = new[]
            {
                new Sample("Name1", "Description1"),
                new Sample("Name2", "Description2"),
                new Sample("Name3", "Description3")
            };
            var database = new SqlCompactDatabaseBuilder()
                           .WithSamplesTable(data)
                           .Build();

            using (database)
            {
                var connectionFactoryMock = new Mock <IDbConnectionFactory>();
                connectionFactoryMock.Setup(f => f.Create())
                .Returns(() => database.CreateConnection());

                // Act
                var sut    = new SampleRepository(connectionFactoryMock.Object);
                var result = sut.Get().ToArray();

                // Assert
                Assert.IsNotNull(result);
                Assert.AreEqual(data.Length, result.Length);
            }
        }
示例#2
0
        public void Get_ById_WithSqlite()
        {
            // Arrange
            var data = new[]
            {
                new Sample("Name1", "Description1"),
                new Sample("Name2", "Description2"),
                new Sample("Name3", "Description3")
            };

            var connection = new SqliteDatabaseBuilder()
                             .WithSamplesTable(data)
                             .Build();

            using (connection)
            {
                var connectionFactoryMock = new Mock <IDbConnectionFactory>();
                connectionFactoryMock.Setup(f => f.Create()).Returns(connection);

                // Act
                var sut    = new SampleRepository(connectionFactoryMock.Object);
                var result = sut.Get(2);

                // Assert
                Assert.IsNotNull(result);
                Assert.AreEqual(2, result.Id);
                Assert.AreEqual(data[1].Name, result.Name);
                Assert.AreEqual(data[1].Description, result.Description);
            }
        }
示例#3
0
        public void Get_AfterRequestToSampleRepository_ShouldReturnSample()
        {
            //Arrange
            var sample = new Sample()
            {
                SampleId = 1, Description = "Description_1", Name = "Name_1"
            };
            var sampleRepo = new SampleRepository(_context);

            sampleRepo.Add(sample);

            //Act
            _context.SaveChanges();
            var expectedSample = sampleRepo.Get(1);

            //Assert
            Assert.That(expectedSample, Is.Not.Null);
            Assert.That(expectedSample.Name, Is.EqualTo(sample.Name));
        }