Exemple #1
0
        public void UnitOfWorkCommits(Company input)
        {
            // Arrange

            var testSettings = new TestProjectSettings();

            DbContext       testContext = null;
            StockUnitOfWork tested      = null;

            try
            {
                testContext = new StockContext(testSettings);
                testContext.Database.EnsureCreated();
                tested = new StockUnitOfWork(testContext);

                // Act

                tested.StockRepository.Add(input);
                tested.Complete();

                var expected = 1;
                var actual   = tested.StockRepository.Count();

                // Assert

                Assert.Equal(expected, actual);
            }
            finally
            {
                testContext?.Database.EnsureDeleted();
                tested?.Dispose();
                testContext?.Dispose();
            }
        }
Exemple #2
0
        static async Task Main()
        {
            var dbName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            var proj   = new ProjectSettings
            {
                ConnectionString =
                    $"server=(localdb)\\MSSQLLocalDB;Initial Catalog={dbName};Integrated Security=True;"
            };
            var input = GetStub();

            DbContext       context = null;
            StockUnitOfWork tested  = null;

            try
            {
                var res = await DbManagementService.EnsureDbExists(proj);

                context = new StockContext(proj);
                tested  = new StockUnitOfWork(context);

                tested.StockRepository.Add(input);
                tested.Complete();

                var actual = tested.StockRepository.Count();

                Console.WriteLine($"Added {actual} record(s) to db");
                Console.ReadKey();
                await DbManagementService.EnsureDbDoesNotExist(proj);
            }
            finally
            {
                tested?.Dispose();
                if (context != null)
                {
                    await context.DisposeAsync();
                }
            }
        }