예제 #1
0
        private SalesController GetController(BasicTestAppDbContext context)
        {
            IAccountData    accountData    = new SqlAccountData(context, _sqlmapper);
            IAccountService accountService = new AccountService(accountData, _mapper);

            return(new SalesController(accountService));
        }
예제 #2
0
        public static BasicTestAppDbContext CreateFreshInMemory()
        {
            // Create a fresh service provider, and therefore a fresh
            // InMemory database instance.
            // We had to do this to avoid the InMemory DB from being dirty after a test added/deleted something.
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();

            BasicTestAppDbContext context = new BasicTestAppDbContext(new DbContextOptionsBuilder <BasicTestAppDbContext>()
                                                                      .UseInMemoryDatabase()
                                                                      .UseInternalServiceProvider(serviceProvider)
                                                                      .Options);

            context.EnsureSeedDataForTest();

            return(context);
        }
예제 #3
0
        public void GetAccountByName_Success()
        {
            using (BasicTestAppDbContext context = CreateInMemorianDB.CreateFreshInMemory())
            {
                //Arrange
                string          userId = "ValidName";
                SalesController ctrl   = GetController(context);

                //Act
                var result = ctrl.Get(userId);

                //Assert
                Assert.IsType <OkObjectResult>(result);

                OkObjectResult objectResult = (OkObjectResult)result;
                Assert.Equal(200, objectResult.StatusCode);
                Assert.IsAssignableFrom <AccountResponseDto>(objectResult.Value);

                AccountResponseDto response = (AccountResponseDto)objectResult.Value;
                Assert.Equal("Test", response.AccountName);
                Assert.True(response.CreatedBy.Contains("Fenix"));
            }
        }
예제 #4
0
 public SqlAccountData(BasicTestAppDbContext context, IMapper mapper)
 {
     _DbContext = context;
     _mapper    = mapper;
 }