示例#1
0
        public async Task GetAllOk()
        {
            var serviceMock = new Mock <IContaService>();

            serviceMock.Setup(m => m.GetAll()).ReturnsAsync(
                new List <ContaDto>
            {
                new ContaDto
                {
                    Id          = Guid.NewGuid(),
                    Name        = "PV Conta",
                    Description = "Conta Corrente",
                    Balance     = 0,
                    Status      = true
                },
                new ContaDto
                {
                    Id          = Guid.NewGuid(),
                    Name        = "PV Conta",
                    Description = "Conta Corrente",
                    Balance     = 0,
                    Status      = true
                }
            }
                );

            _controller = new ContasController(serviceMock.Object);

            var result = await _controller.GetAll();

            Assert.True(result is OkObjectResult);
        }
示例#2
0
        public async Task GetAllBadRequest()
        {
            var serviceMock = new Mock <IContaService>();

            serviceMock.Setup(m => m.GetAll()).ReturnsAsync(
                new List <ContaDto>
            {
                new ContaDto
                {
                    Id          = Guid.NewGuid(),
                    Name        = "PV Conta",
                    Description = "Conta Corrente",
                    Balance     = 0,
                    Status      = true
                },
                new ContaDto
                {
                    Id          = Guid.NewGuid(),
                    Name        = "PV Conta",
                    Description = "Conta Corrente",
                    Balance     = 0,
                    Status      = true
                }
            }
                );

            _controller = new ContasController(serviceMock.Object);
            _controller.ModelState.AddModelError("Id", "Formato Inválido");

            var result = await _controller.GetAll();

            Assert.True(result is BadRequestObjectResult);
        }
示例#3
0
        public async Task ReturnsList()
        {
            var optionsBuilder = new DbContextOptionsBuilder <DataContext>();

            optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ContasDatabase;Trusted_Connection=True;MultipleActiveResultSets=true");
            var context = new DataContext(optionsBuilder.Options);

            var service = new ContaService(context);
            var sut     = new ContasController(new NullLogger <ContasController>(), service);
            var result  = await sut.GetAll() as ObjectResult;

            Assert.IsType <List <ContaAjustada> >(result.Value);
            Assert.Equal(200, result.StatusCode);
        }