Beispiel #1
0
        public void GenerarDiagnosticoCuandoExistenDetalles()
        {
            var context = ApplicationDbContextInMemory.Get();

            var eventHandler = new DiagnosticoCreateEventHandler(context, GetLogger);

            string expectedResult = "rubeola";

            var diagnostico = new DiagnosticoCreateCommand
            {
                DetallesDiagnostico = new List <DetalleDiagnosticoCreate>
                {
                    new DetalleDiagnosticoCreate
                    {
                        Sintoma = "fiebre",
                    },
                    new DetalleDiagnosticoCreate
                    {
                        Sintoma = "escalofrios",
                    },
                    new DetalleDiagnosticoCreate
                    {
                        Sintoma = "dolorcabeza",
                    },
                    new DetalleDiagnosticoCreate
                    {
                        Sintoma = "ojosrojos",
                    }
                }
            };

            string actualResult = eventHandler.DeterminarEnfermedad(diagnostico);

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void IntentarAgregarStockCuandoProductoExiste()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productoId = 5;

            context.Stocks.Add(new ProductoEnStock
            {
                ProductoEnStockId = 5,
                ProductoId        = productoId,
                Stock             = 3
            });

            context.SaveChanges();

            var handler = new ProductoEnStockActualizarEventHandler(context, GetLogger);

            handler.Handle(new ProductoEnStockActualizarComnando
            {
                Items = new List <ProductoEnStockActualizarItem>()
                {
                    new ProductoEnStockActualizarItem {
                        ProductoId = productoId,
                        Stock      = 3,
                        Accion     = ProductoEnStockAccion.Add
                    }
                }
            }, new CancellationToken()).Wait();

            var stockIdDb = context.Stocks.Single(x => x.ProductoId == productoId).Stock;

            Assert.AreEqual(stockIdDb, 6);
        }
Beispiel #3
0
        public void TryCreateClientWhenExists()
        {
            var context = ApplicationDbContextInMemory.Get();

            var name = "Client 104";

            var handler = new ClientCreateEventHandler(context, GetLogger);

            handler.Handle(new ClientCreateCommand
            {
                Name = name
            }, new CancellationToken()).Wait();

            try
            {
                handler = new ClientCreateEventHandler(context, GetLogger);
                handler.Handle(new ClientCreateCommand
                {
                    Name = name
                }, new CancellationToken()).Wait();

                var clientInDb = context.Clients.Single(x => x.Name == name).Name;
            }
            catch (AggregateException ae)
            {
                var exception = ae.GetBaseException();

                if (exception is ClientCreateCommandException)
                {
                    throw new ClientCreateCommandException(exception.Message);
                }
            }
        }
Beispiel #4
0
        public async Task TryToSubstractStockWhenProductHasStock()
        {
            var dbContext        = ApplicationDbContextInMemory.Get();
            var productInStockId = 1;
            var productId        = 1;

            dbContext.Stocks.Add(new ProductInStock
            {
                ProductId        = productId,
                ProductInStockId = productInStockId,
                Stock            = 1
            });

            dbContext.SaveChanges();

            var handler = new ProductInStockUpdateStockEventHandler(dbContext, logger);
            await handler.Handle(new ProductInStockUpdateStockCommand()
            {
                Items = new List <ProductInStockUpdateItem>()
                {
                    new ProductInStockUpdateItem()
                    {
                        ProductId = productId,
                        Stock     = 1,
                        Action    = ProductInStockAction.Substract
                    }
                }
            }, CancellationToken.None);

            var p = dbContext.Stocks.Find(productId);

            Assert.Equals(p.Stock, 0);
        }
Beispiel #5
0
        public void GivenUnDiagnosticoConElIdAgregadoEnLaBaseDeDatos(int id)
        {
            Context = ApplicationDbContextInMemory.Get();

            IdDiagnostico = id;

            Domain.Diagnostico diagnostico = new()
            {
                Empleado_Id = 1,
                Paciente_Id = 1,
                Fecha       = DateTime.UtcNow,
                Enfermedad  = "gripe"
            };

            diagnostico.DetallesDiagnostico.Add(
                new Domain.DetalleDiagnostico()
            {
                Diagnostico    = diagnostico,
                Diagnostico_Id = diagnostico.Id,
                Sintoma        = "tos"
            }
                );

            Context.Diagnosticos.Add(diagnostico);
            Context.SaveChanges();
        }
        public void TryToAddStockWhenProductExists()
        {
            var _context = ApplicationDbContextInMemory.Get();

            int    productId        = 5;
            int    productInStockId = 5;
            double stock            = 1;

            _context.Stocks.Add(new Domain.ProductInStock
            {
                ProductId        = productId,
                ProductInStockId = productInStockId,
                Stock            = stock
            });

            _context.SaveChanges();

            var handler = new ProductInStockUpdateStockEventHandler(_context, GetLogger);

            handler.Handle(new ProductInStockUpdateStockCommand
            {
                Items = new List <ProductInStockUpdateItem>()
                {
                    new ProductInStockUpdateItem {
                        ProductId = productId,
                        Stock     = 2,
                        Action    = Common.Enums.ProductInStockAction.Add
                    }
                }
            }, new System.Threading.CancellationToken()).Wait();

            var stockInDb = _context.Stocks.Single(x => x.ProductId == productId).Stock;

            Assert.AreEqual(stockInDb, 3);
        }
        public void TryToSubstractStockWhenProductHasStock()
        {
            var _context = ApplicationDbContextInMemory.Get();

            int    productId        = 1;
            int    productInStockId = 1;
            double stock            = 1;

            _context.Stocks.Add(new Domain.ProductInStock
            {
                ProductId        = productId,
                ProductInStockId = productInStockId,
                Stock            = stock
            });

            _context.SaveChanges();

            var handler = new ProductInStockUpdateStockEventHandler(_context, GetLogger);

            handler.Handle(new ProductInStockUpdateStockCommand
            {
                Items = new List <ProductInStockUpdateItem>()
                {
                    new ProductInStockUpdateItem {
                        ProductId = productId,
                        Stock     = stock,
                        Action    = Common.Enums.ProductInStockAction.Substract
                    }
                }
            }, new System.Threading.CancellationToken()).Wait();
        }
Beispiel #8
0
        public async Task TryToSubstractStockWhenProductHasStock()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productInStockId = 1;
            var productId        = 1;

            // Add product
            context.Stocks.Add(new ProductInStock {
                ProductInStockId = productInStockId,
                ProductId        = productId,
                Stock            = 1
            });

            context.SaveChanges();

            var command = new ProductInStockUpdateStockEventHandler(context, GetIlogger);

            await command.Handle(new ProductInStockUpdateStockCommand {
                Items = new List <ProductInStockUpdateItem> {
                    new ProductInStockUpdateItem {
                        ProductId = 1,
                        Stock     = 1,
                        Action    = Common.Enums.ProductInStockAction.Substract
                    }
                }
            }, new System.Threading.CancellationToken());
        }
        public void TryToAddStockWhenProductExists()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productInStockId = 3;
            var productId        = 3;

            context.Stocks.Add(new ProductInStock
            {
                ProductInStockId = productInStockId,
                ProductId        = productId,
                Stock            = 1
            });

            context.SaveChanges();

            var handler = new ProductInStockUpdateStockEventHandler(context, GetLogger);

            handler.Handle(new ProductInStockUpdateStockCommand
            {
                Items = new List <ProductInStockUpdateItem>()
                {
                    new ProductInStockUpdateItem {
                        ProductId = productId,
                        Stock     = 2,
                        Action    = ProductInStockAction.Add
                    }
                }
            }, new CancellationToken()).Wait();

            var stockInDb = context.Stocks.Single(x => x.ProductId == productId).Stock;

            Assert.AreEqual(stockInDb, 3);
        }
Beispiel #10
0
        public void TryToAddStockWhenProductExists()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productInStockId = 3;
            var productId        = 3;

            // Add product
            context.Stocks.Add(new ProductInStock
            {
                ProductInStockId = productInStockId,
                ProductId        = productId,
                Stock            = 1
            });

            context.SaveChanges();

            var command = new ProductInStockUpdateStockEventHandler(context, GetIlogger);

            command.Handle(new ProductInStockUpdateStockCommand
            {
                Items = new List <ProductInStockUpdateItem> {
                    new ProductInStockUpdateItem {
                        ProductId = productId,
                        Stock     = 2,
                        Action    = Common.Enums.ProductInStockAction.Add
                    }
                }
            }, new System.Threading.CancellationToken()).Wait();

            Assert.AreEqual(context.Stocks.First(x => x.ProductInStockId == productInStockId).Stock, 3);
        }
        public void TryToSubstractStockWhenProductHasStock()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productInStockId = 1;
            var productId        = 1;

            context.Stocks.Add(new ProductInStock
            {
                ProductInStockId = productInStockId,
                ProductId        = productId,
                Stock            = 1
            });

            context.SaveChanges();

            var handler = new ProductInStockUpdateStockEventHandler(context, GetLogger);

            handler.Handle(new ProductInStockUpdateStockCommand {
                Items = new List <ProductInStockUpdateItem>()
                {
                    new ProductInStockUpdateItem {
                        ProductId = productId,
                        Stock     = 1,
                        Action    = ProductInStockAction.Substract
                    }
                }
            }, new CancellationToken()).Wait();
        }
        public void IntentarSustraerStockCuandoProductoTieneStock()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productoId = 1;
            var stock      = 1;

            context.Stocks.Add(new ProductoEnStock
            {
                ProductoEnStockId = 1,
                ProductoId        = productoId,
                Stock             = stock
            });

            context.SaveChanges();

            var handler = new ProductoEnStockActualizarEventHandler(context, GetLogger);

            handler.Handle(new ProductoEnStockActualizarComnando {
                Items = new List <ProductoEnStockActualizarItem>()
                {
                    new ProductoEnStockActualizarItem {
                        ProductoId = productoId,
                        Stock      = stock,
                        Accion     = ProductoEnStockAccion.Substract
                    }
                }
            }, new CancellationToken()).Wait();
        }
        public void testActualizarPersonaNoExistente()
        {
            var context = ApplicationDbContextInMemory.Get();
            var handler = new PersonaUpdateEventHandler(context, GetLogger);

            try
            {
                handler.Handle(new PersonaUpdateCommand
                {
                    PersonaID       = 99,
                    Nombres         = "NO EXISTO",
                    Apellidos       = "SAAVEDRA CASTRO",
                    FechaNacimiento = "13/06/1989",
                    TipoDocumento   = "DNI",
                    Documento       = 206022332332
                }, new System.Threading.CancellationToken()).Wait();
            }
            catch (AggregateException ae)
            {
                var exception = ae.GetBaseException();

                if (exception is PersonaUpdateEventHandlerException)
                {
                    throw new PersonaUpdateEventHandlerException(exception?.InnerException?.Message);
                }
            }
        }
        public void TryToAddStockWhenProductNotExists()
        {
            ApplicationDBContext context = ApplicationDbContextInMemory.Get();

            int productId = 4;

            ProductInStockUpdateStockEventHandler handler = new ProductInStockUpdateStockEventHandler(context, GetLogger);

            handler.Handle(new ProductInStockUpdateStockCommand
            {
                Items = new List <ProductInStockUpdateItem>()
                {
                    new ProductInStockUpdateItem
                    {
                        ProductId = productId,
                        Stock     = 2,
                        Action    = Common.ProductInStockAction.Add
                    }
                }
            }, new CancellationToken()).Wait();

            var stockInDb = context.Stocks.Single(item => item.ProductId == productId).Stock;

            Assert.AreEqual(stockInDb, 2);
        }
Beispiel #15
0
        public void GivenUnaBaseDeDatosSinDiagnosticosRegistrados(int id)
        {
            IdDiagnostico = id;

            Context = ApplicationDbContextInMemory.Get();

            if (Context.Diagnosticos.ToList().Exists(x => x.Id == id))
            {
                Context.Diagnosticos.Remove(Context.Diagnosticos.Find(id));
                Context.SaveChanges();
            }
        }
Beispiel #16
0
        public void GenerarDiagnosticoCuandoNoExistenDetalles()
        {
            var context = ApplicationDbContextInMemory.Get();

            var eventHandler = new DiagnosticoCreateEventHandler(context, GetLogger);

            var diagnostico = new DiagnosticoCreateCommand
            {
                DetallesDiagnostico = new List <DetalleDiagnosticoCreate>()
            };

            eventHandler.DeterminarEnfermedad(diagnostico);
        }
        public async Task TryToGetACustomerThatNotExists()
        {
            // Retrieve DbContext
            var context = ApplicationDbContextInMemory.Get();
            ICustomerQueryService queryService = new CustomerQueryService(context, GetIlogger);

            // Test customer
            var testCustomerId = 99999999;

            // Retrieve the new record by USD code
            var record = await queryService.GetAsync(testCustomerId);

            // Check
            Assert.IsNull(record);
        }
        public async Task TryToRemoveACustomerThatDoesntExists()
        {
            // Retrieve DbContext
            var context = ApplicationDbContextInMemory.Get();
            var handler = new CustomerRemoveEventHandler(context);

            // Set test customer
            var testCustomerId = 999999999;

            // Retrieve from database
            await handler.Handle(new CustomerRemoveCommand
            {
                CustomerId = testCustomerId
            }, new CancellationToken());
        }
Beispiel #19
0
        public void TryCreateClientWhenNotExists()
        {
            var context = ApplicationDbContextInMemory.Get();

            var name = "Client 103";

            var handler = new ClientCreateEventHandler(context, GetLogger);

            handler.Handle(new ClientCreateCommand
            {
                Name = name
            }, new CancellationToken()).Wait();

            var clientInDb = context.Clients.Single(x => x.Name == name).Name;

            Assert.AreNotEqual(clientInDb, "name");
        }
        public void TryToSubstractStockWhenProductHasntStock()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productInStockId = 2;
            var productId        = 2;

            context.Stocks.Add(new ProductInStock
            {
                ProductInStockId = productInStockId,
                ProductId        = productId,
                Stock            = 1
            });

            context.SaveChanges();

            var handler = new ProductInStockUpdateStockEventHandler(context, GetLogger);


            try
            {
                handler.Handle(new ProductInStockUpdateStockCommand
                {
                    Items = new List <ProductInStockUpdateItem>()
                    {
                        new ProductInStockUpdateItem {
                            ProductId = productId,
                            Stock     = 2,
                            Action    = ProductInStockAction.Substract
                        }
                    }
                }, new CancellationToken()).Wait();
            }

            catch (AggregateException ae)
            {
                var exception = ae.GetBaseException();

                if (exception is ProducInStockUpdateStockCommandException)
                {
                    throw new ProducInStockUpdateStockCommandException(exception?.InnerException?.Message);
                }
            }
        }
        public void IntentarSustraerStockCuandoProductoNoTieneStock()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productoId = 2;
            var stock      = 1;

            context.Stocks.Add(new ProductoEnStock
            {
                ProductoEnStockId = 2,
                ProductoId        = productoId,
                Stock             = stock
            });

            context.SaveChanges();

            var handler = new ProductoEnStockActualizarEventHandler(context, GetLogger);

            try
            {
                handler.Handle(new ProductoEnStockActualizarComnando
                {
                    Items = new List <ProductoEnStockActualizarItem>()
                    {
                        new ProductoEnStockActualizarItem
                        {
                            ProductoId = productoId,
                            Stock      = 2,
                            Accion     = ProductoEnStockAccion.Substract
                        }
                    }
                }, new CancellationToken()).Wait();
            }
            catch (AggregateException ae)
            {
                var excepcion = ae.GetBaseException();

                if (excepcion is ProductoEnStockActualizarComnandoExcepcion)
                {
                    throw new ProductoEnStockActualizarComnandoExcepcion(excepcion?.InnerException?.Message);
                }
            }
        }
Beispiel #22
0
        public async Task TryToCreateANewCustomerAndCheckReferencesToWhoCreatedIt()
        {
            // Retrieve DbContext
            var context = ApplicationDbContextInMemory.Get();
            var handler = new CustomerCreateEventHandler(context);

            // Insert record
            var lastInsertId = await handler.Handle(new CustomerCreateCommand
            {
                Name    = "Test",
                Surname = "Surname"
            }, new CancellationToken());

            // Retrieve from database
            var entry = context.Customers.SingleOrDefault(x => x.CustomerId == lastInsertId);

            // Check
            Assert.IsTrue(entry.CreatedBy != null && entry.CreatedAt != null);
        }
        public async Task TryToRemoveACustomer()
        {
            // Retrieve DbContext
            var context = ApplicationDbContextInMemory.Get();
            var handler = new CustomerRemoveEventHandler(context);

            // Get test customer
            var testCustomerId = GetTestCustomerId(context);

            // Retrieve from database
            await handler.Handle(new CustomerRemoveCommand
            {
                CustomerId = testCustomerId
            }, new CancellationToken());

            var entry = context.Customers.SingleOrDefault(x => x.CustomerId == testCustomerId);

            // Check
            Assert.IsNull(entry);
        }
        public void TryToSubstractStockWhenProductHasntStock()
        {
            var _context = ApplicationDbContextInMemory.Get();

            int    productId        = 6;
            int    productInStockId = 6;
            double stock            = 1;

            _context.Stocks.Add(new Domain.ProductInStock
            {
                ProductId        = productId,
                ProductInStockId = productInStockId,
                Stock            = stock
            });

            _context.SaveChanges();
            try
            {
                var handler = new ProductInStockUpdateStockEventHandler(_context, GetLogger);

                handler.Handle(new ProductInStockUpdateStockCommand
                {
                    Items = new List <ProductInStockUpdateItem>()
                    {
                        new ProductInStockUpdateItem {
                            ProductId = productId,
                            Stock     = 3,
                            Action    = Common.Enums.ProductInStockAction.Substract
                        }
                    }
                }, new System.Threading.CancellationToken()).Wait();
            }
            catch (AggregateException ae)
            {
                var exception = ae.GetBaseException();
                if (exception is ProductInStockUpdateStockCommandException)
                {
                    throw new ProductInStockUpdateStockCommandException(exception?.InnerException?.Message);
                }
            }
        }
Beispiel #25
0
        public void TryToSubstractStockWhenProductHasntStock()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productInStockId = 2;
            var productId        = 2;

            // Add product
            context.Stocks.Add(new ProductInStock
            {
                ProductInStockId = productInStockId,
                ProductId        = productId,
                Stock            = 1
            });

            context.SaveChanges();

            var command = new ProductInStockUpdateStockEventHandler(context, GetIlogger);

            try
            {
                command.Handle(new ProductInStockUpdateStockCommand
                {
                    Items = new List <ProductInStockUpdateItem> {
                        new ProductInStockUpdateItem {
                            ProductId = productId,
                            Stock     = 2,
                            Action    = Common.Enums.ProductInStockAction.Substract
                        }
                    }
                }, new System.Threading.CancellationToken()).Wait();
            }
            catch (AggregateException ae)
            {
                if (ae.GetBaseException() is ProductInStockUpdateStockCommandException)
                {
                    throw new ProductInStockUpdateStockCommandException(ae.InnerException?.Message);
                }
            }
        }
Beispiel #26
0
        public async Task TryToAttachAnImageToCustomer()
        {
            // Retrieve DbContext
            var context = ApplicationDbContextInMemory.Get();
            var handler = new CustomerImageEventHandler(context, GetImageUploadService);

            // Retrieve customer to Update
            var testCustomerId = GetTestCustomerId(context);

            // Update customer
            await handler.Handle(new CustomerImageUploadCommand
            {
                CustomerId = testCustomerId,
                File       = GetIFormFile
            }, new CancellationToken());

            // Retrieve updated customer
            var modifiedEntry = context.Customers.Single(x => x.CustomerId == testCustomerId);

            // Check
            Assert.IsNotNull(modifiedEntry.Photo != null);
        }
Beispiel #27
0
        public void GivenDiagnosticosRegistradosEnLaBaseDeDatos(int cantidad)
        {
            Context = ApplicationDbContextInMemory.Get();

            Domain.Diagnostico diagnostico = new()
            {
                Empleado_Id = 1,
                Paciente_Id = 1,
                Fecha       = DateTime.UtcNow,
                Enfermedad  = "gripe"
            };

            diagnostico.DetallesDiagnostico.Add(
                new Domain.DetalleDiagnostico()
            {
                Diagnostico    = diagnostico,
                Diagnostico_Id = diagnostico.Id,
                Sintoma        = "tos"
            }
                );

            diagnostico.DetallesDiagnostico.Add(
                new Domain.DetalleDiagnostico()
            {
                Diagnostico    = diagnostico,
                Diagnostico_Id = diagnostico.Id,
                Sintoma        = "tos"
            }
                );

            // se agregan dos diagnosticos
            for (int i = 0; i < cantidad; i++)
            {
                Context.Diagnosticos.Add(diagnostico);
            }

            Context.SaveChanges();
        }
        public async Task TryToUpdateACustomerAndCheckReferencesToWhoUpdatedIt()
        {
            // Retrieve DbContext
            var context = ApplicationDbContextInMemory.Get();
            var handler = new CustomerUpdateEventHandler(context);

            // Retrieve customer to Update
            var testCustomerId = GetTestCustomerId(context);

            // Update customer
            await handler.Handle(new CustomerUpdateCommand
            {
                CustomerId = testCustomerId,
                Name       = "Test modified",
                Surname    = "Surname modified"
            }, new CancellationToken());

            // Retrieve updated customer
            var modifiedEntry = context.Customers.Single(x => x.CustomerId == testCustomerId);

            // Check
            Assert.IsNotNull(modifiedEntry.UpdatedBy != null && modifiedEntry.UpdatedAt != null);
        }
        public void TryToAddStockWhenProductNotExist()
        {
            var context = ApplicationDbContextInMemory.Get();

            var productId = 4;

            var handle = new ProductInStockUpdateStockEventHandler(context, GetLogger);

            handle.Handle(new ProductInStockUpdateStockCommand
            {
                Items = new List <ProductInStockUpdateItem>()
                {
                    new ProductInStockUpdateItem {
                        ProductId = productId,
                        Action    = Common.Enums.ProductInStockAction.Add,
                        Stock     = 2
                    }
                }
            }, new CancellationToken()).Wait();

            var stockInDb = context.Stocks.Single(x => x.ProductId == productId).Stock;

            Assert.AreEqual(stockInDb, 2);
        }