Exemple #1
0
        public async Task CreatesEntry()
        {
            var optionsBuilder = new DbContextOptionsBuilder <DataContext>();

            optionsBuilder.UseInMemoryDatabase("InMemoryDatabaseName").ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning));
            var context = new DataContext(optionsBuilder.Options);

            var service = new ContaService(context);
            var sut     = new ContasController(new NullLogger <ContasController>(), service);
            var result  = await sut.Create(new Conta
            {
                Nome       = "Conta",
                Valor      = 20.8m,
                Vencimento = new DateTime(2020, 12, 10),
                Pagamento  = new DateTime(2020, 12, 20)
            }) as StatusCodeResult;

            Assert.Equal(200, result.StatusCode);
        }
Exemple #2
0
        public async Task FailsToCreateEntry()
        {
            var optionsBuilder = new DbContextOptionsBuilder <DataContext>();

            optionsBuilder.UseInMemoryDatabase("InMemoryDatabaseName");
            var context = new DataContext(optionsBuilder.Options);

            var service = new ContaService(context);
            var sut     = new ContasController(new NullLogger <ContasController>(), service);
            var result  = await sut.Create(new Conta
            {
                Nome       = "",
                Valor      = 0,
                Vencimento = new DateTime(2020, 12, 10),
                Pagamento  = new DateTime(2020, 12, 20)
            }) as ObjectResult;

            Assert.Equal(400, result.StatusCode);
        }
Exemple #3
0
        public async Task CreatesEntry()
        {
            var optionsBuilder = new DbContextOptionsBuilder <DataContext>();

            optionsBuilder.UseInMemoryDatabase("InMemoryDatabaseName");
            var context   = new DataContext(optionsBuilder.Options);
            var contaRepo = new ContaRepository(context);
            var regraRepo = new RegraRepository(context);

            var service = new ContaService(contaRepo, regraRepo);
            var sut     = new ContasController(service, new NullLogger <ContasController>());
            var result  = await sut.Create(new ContaTransfer
            {
                Nome       = "Conta",
                Valor      = 20.8m,
                Vencimento = new DateTime(2020, 12, 10),
                Pagamento  = new DateTime(2020, 12, 20)
            }) as ObjectResult;

            Assert.Equal(200, result.StatusCode);
        }