Exemplo n.º 1
0
        private InventoryFormData AddInventoryFormData(Form form)
        {
            var formData =
                new InventoryFormData()
            {
                Form     = form,
                ShipDate = new Question {
                    Caption = "Ship Date", DataType = QuestionDataType.Date, Form = form
                },
                BatchNumber = new Question {
                    Caption = "Batch Number", DataType = QuestionDataType.Integer, Form = form
                },
                QuantityShipped = new Question {
                    Caption = "Quantity Shipped", DataType = QuestionDataType.Number, Form = form
                },
                ReceiptDate = new Question {
                    Caption = "Receipt Date", DataType = QuestionDataType.Date, Form = form
                },
                MedicationUsage = new List <RepeatableInventoryData>()
            };

            InventoryFormDataRepository.Add(formData);
            QuestionRepository.Add(formData.ShipDate);
            QuestionRepository.Add(formData.BatchNumber);
            QuestionRepository.Add(formData.QuantityShipped);
            QuestionRepository.Add(formData.ReceiptDate);
            return(formData);
        }
        private void FillInvetnoryFormMedicationUsage(double quantityShipped, DateTime shipDate,
                                                      InventoryFormData inventoryFormData)
        {
            int      usagesCount     = randomGenerator.Next(1, 4);
            double   quantityPerTime = Math.Round(quantityShipped / usagesCount, 1);
            DateTime nextUsage       = shipDate.AddDays(randomGenerator.Next(4));

            inventoryFormData.MedicationUsage = new List <RepeatableInventoryData>();

            for (int i = 0; i < usagesCount - 1; i++)
            {
                inventoryFormData.MedicationUsage.Add(new RepeatableInventoryData {
                    DateUsed =
                        new Question()
                    {
                        Caption = "Date Used", DataType = QuestionDataType.Date, Value = nextUsage.ToString()
                    },
                    QuantityUsed =
                        new Question()
                    {
                        Caption = "Quantity Used", DataType = QuestionDataType.Number, Value = quantityPerTime.ToString()
                    }
                });
                nextUsage = nextUsage.AddDays(randomGenerator.Next(1, 3));
            }
            double restOfMedication = quantityShipped - Math.Round(quantityPerTime * (usagesCount - 1), 1);

            restOfMedication = Math.Round(restOfMedication, 1);
            inventoryFormData.MedicationUsage.Add(new RepeatableInventoryData {
                DateUsed =
                    new Question()
                {
                    Caption = "Date Used", DataType = QuestionDataType.Date, Value = nextUsage.ToString()
                },
                QuantityUsed =
                    new Question()
                {
                    Caption = "Quantity Used", DataType = QuestionDataType.Number, Value = restOfMedication.ToString()
                }
            });
        }
        public void InventoryFormDataToViewModel_FullData()
        {
            //Arrange
            var iFormData = new InventoryFormData {
                Id   = 5,
                Form =
                    new Form {
                    Id        = 15,
                    Caption   = "Form15",
                    FormState = FormState.Completed,
                    Visit     =
                        new Visit {
                        Caption = "Visit15", Patient = new Patient {
                            PatientNumber = 150
                        }
                    }
                },
                ShipDate =
                    new Question {
                    Id       = 3,
                    DataType = QuestionDataType.Date,
                    Value    =
                        new DateTime(2011, 12, 21).ToString(
                            CultureInfo.InvariantCulture)
                },
                BatchNumber =
                    new Question {
                    Id = 4, DataType = QuestionDataType.Integer, Value = "123"
                },
                QuantityShipped =
                    new Question {
                    Id       = 5,
                    DataType = QuestionDataType.Number,
                    Value    = (3.3m).ToString(CultureInfo.InvariantCulture)
                },
                ReceiptDate =
                    new Question {
                    Id       = 6,
                    DataType = QuestionDataType.Date,
                    Value    =
                        new DateTime(2011, 12, 5).ToString(
                            CultureInfo.InvariantCulture)
                },
                MedicationUsage =
                    new List <RepeatableInventoryData> {
                    new RepeatableInventoryData {
                        Id       = 1,
                        DateUsed =
                            new Question {
                            Id       = 114,
                            DataType = QuestionDataType.Date,
                            Value    = DateTime.Today.ToString(CultureInfo.InvariantCulture)
                        },
                        QuantityUsed =
                            new Question {
                            Id       = 115,
                            DataType = QuestionDataType.Number,
                            Value    = (2.4m).ToString(CultureInfo.InvariantCulture)
                        }
                    },
                    new RepeatableInventoryData {
                        Id       = 2,
                        DateUsed = new Question {
                            Id       = 211,
                            DataType = QuestionDataType.Date,
                            Value    = DateTime.Today.AddDays(-1).ToString(CultureInfo.InvariantCulture)
                        },
                        QuantityUsed =
                            new Question {
                            Id       = 212,
                            DataType = QuestionDataType.Number,
                            Value    = (0.4m).ToString(CultureInfo.InvariantCulture)
                        }
                    }
                }
            };
            //Act
            var inventory = formController.MapInventoryFormDataToViewModel(iFormData);

            //Assert
            Assert.That(inventory.FormId, Is.EqualTo(15));
            Assert.That(inventory.FormCaption, Is.EqualTo("Form15"));
            Assert.That(inventory.IsCompleted, Is.True);
            Assert.That(inventory.VisitName, Is.EqualTo("Visit15"));
            Assert.That(inventory.PatientNumber, Is.EqualTo(150));
            Assert.That(inventory.Id, Is.EqualTo(5));
            Assert.That(inventory.BatchNumber, Is.EqualTo(123));
            Assert.That(inventory.ShipDate, Is.Not.Null);
            Assert.That(inventory.ShipDate.Value.ToShortDateString(), Is.EqualTo(new DateTime(2011, 12, 21).ToShortDateString()));
            Assert.That(inventory.ReceiptDate, Is.Not.Null);
            Assert.That(inventory.ReceiptDate.Value.ToShortDateString(),
                        Is.EqualTo(new DateTime(2011, 12, 5).ToShortDateString()));
            Assert.That(inventory.QuantityShipped, Is.EqualTo(3.3m));


            Assert.That(inventory.BatchNumberQuestionId, Is.EqualTo(iFormData.BatchNumber.Id));
            Assert.That(inventory.ShipDateQuestionId, Is.EqualTo(iFormData.ShipDate.Id));
            Assert.That(inventory.ReceiptDateQuestionId, Is.EqualTo(iFormData.ReceiptDate.Id));
            Assert.That(inventory.QuantityShippedQuestionId, Is.EqualTo(iFormData.QuantityShipped.Id));


            Assert.That(inventory.MedicationUsage, Is.Not.Null);
            Assert.That(inventory.MedicationUsage.Count, Is.EqualTo(2));

            Assert.That(inventory.MedicationUsage[0].DateUsed, Is.Not.Null);
            Assert.That(inventory.MedicationUsage[0].DateUsed.Value.ToShortDateString(),
                        Is.EqualTo(DateTime.Today.ToShortDateString()));
            Assert.That(inventory.MedicationUsage[0].QuantityUsed, Is.EqualTo(2.4m));

            Assert.That(inventory.MedicationUsage[0].DateUsedQuestionId, Is.EqualTo(iFormData.MedicationUsage[0].DateUsed.Id));
            Assert.That(inventory.MedicationUsage[0].QuantityUsedQuestionId,
                        Is.EqualTo(iFormData.MedicationUsage[0].QuantityUsed.Id));

            Assert.That(inventory.MedicationUsage[1].DateUsed, Is.Not.Null);
            Assert.That(inventory.MedicationUsage[1].DateUsed.Value.ToShortDateString(),
                        Is.EqualTo(DateTime.Today.AddDays(-1).ToShortDateString()));
            Assert.That(inventory.MedicationUsage[1].QuantityUsed, Is.EqualTo(0.4m));

            Assert.That(inventory.MedicationUsage[1].DateUsedQuestionId, Is.EqualTo(iFormData.MedicationUsage[1].DateUsed.Id));
            Assert.That(inventory.MedicationUsage[1].QuantityUsedQuestionId,
                        Is.EqualTo(iFormData.MedicationUsage[1].QuantityUsed.Id));
        }
        public void UpdateMedicationUsage_AddOneDeleteOneQuestions()
        {
            //Arrange
            var dataStorage = new Mock <IDataStorage>();

            var entity = new InventoryFormData()
            {
                Id = 1,
                QuantityShipped = new Question {
                    Id = 2, Value = "2"
                },
                BatchNumber = new Question {
                    Id = 3, Value = "3"
                },
                ReceiptDate = new Question {
                    Id = 4, Value = "4"
                },
                ShipDate = new Question {
                    Id = 5, Value = "5"
                },
                MedicationUsage = new List <RepeatableInventoryData> {
                    new RepeatableInventoryData {
                        Id       = 1,
                        DateUsed =
                            new Question {
                            Id    = 6,
                            Value = "6"
                        },
                        QuantityUsed =
                            new Question {
                            Id    = 7,
                            Value = "7"
                        }
                    },
                    new RepeatableInventoryData {
                        Id       = 2,
                        DateUsed = new Question {
                            Id    = 8,
                            Value = "8"
                        },
                        QuantityUsed =
                            new Question {
                            Id    = 9,
                            Value = "9"
                        }
                    }
                }
            };
            var updatedEntity = new InventoryFormData()
            {
                Id = 1,
                QuantityShipped = new Question {
                    Id = 3, Value = "3"
                },
                BatchNumber = new Question {
                    Id = 4, Value = "4"
                },
                ReceiptDate = new Question {
                    Id = 5, Value = "5"
                },
                ShipDate = new Question {
                    Id = 6, Value = "6"
                },
                MedicationUsage = new List <RepeatableInventoryData> {
                    new RepeatableInventoryData {
                        Id       = 2,
                        DateUsed =
                            new Question {
                            Id    = 10,
                            Value = "10"
                        },
                        QuantityUsed =
                            new Question {
                            Id    = 11,
                            Value = "11"
                        }
                    },
                    new RepeatableInventoryData {
                        Id       = 0,
                        DateUsed =
                            new Question {
                            Id    = 12,
                            Value = "12"
                        },
                        QuantityUsed =
                            new Question {
                            Id    = 13,
                            Value = "13"
                        }
                    }
                }
            };


            var repository = new InventoryFormDataRepository(dataStorage.Object);

            dataStorage.Setup(ds => ds.GetData <InventoryFormData>()).Returns(new List <InventoryFormData> {
                entity
            });

            //Act
            repository.Edit(updatedEntity);
            //Assert
            //Values are equal
            Assert.That(entity.MedicationUsage, Is.Not.Null);
            Assert.That(entity.MedicationUsage.Count, Is.EqualTo(2));
            Assert.That(entity.MedicationUsage.Count, Is.EqualTo(updatedEntity.MedicationUsage.Count));
            Assert.That(entity.MedicationUsage.Any(x => x.Id == 1), Is.False);
            Assert.That(entity.MedicationUsage.Any(x => x.Id == 2), Is.True);
            Assert.That(entity.MedicationUsage.Any(x => x.Id == 3), Is.True);
            Assert.That(entity.MedicationUsage[0].Id, Is.EqualTo(updatedEntity.MedicationUsage[0].Id));
            Assert.That(entity.MedicationUsage[0].DateUsed.Value, Is.EqualTo(updatedEntity.MedicationUsage[0].DateUsed.Value));
            Assert.That(entity.MedicationUsage[0].QuantityUsed.Value,
                        Is.EqualTo(updatedEntity.MedicationUsage[0].QuantityUsed.Value));
            Assert.That(entity.MedicationUsage[1].Id, Is.EqualTo(updatedEntity.MedicationUsage[1].Id));
            Assert.That(entity.MedicationUsage[1].DateUsed.Value, Is.EqualTo(updatedEntity.MedicationUsage[1].DateUsed.Value));
            Assert.That(entity.MedicationUsage[1].QuantityUsed.Value,
                        Is.EqualTo(updatedEntity.MedicationUsage[1].QuantityUsed.Value));
        }
        public void MappingTest()
        {
            //Arrange
            var dataStorage = new Mock <IDataStorage>();
            var entity      = new InventoryFormData()
            {
                Id = 1,
                QuantityShipped = new Question {
                    Id = 2, Value = "2"
                },
                BatchNumber = new Question {
                    Id = 3, Value = "3"
                },
                ReceiptDate = new Question {
                    Id = 4, Value = "4"
                },
                ShipDate = new Question {
                    Id = 5, Value = "5"
                },
                MedicationUsage = new List <RepeatableInventoryData> {
                    new RepeatableInventoryData {
                        Id       = 1,
                        DateUsed =
                            new Question
                        {
                            Id = 6, Value = "6"
                        },
                        QuantityUsed =
                            new Question
                        {
                            Id = 7, Value = "7"
                        }
                    }
                }
            };
            var updatedEntity = new InventoryFormData()
            {
                Id = 1,
                QuantityShipped = new Question {
                    Id = 3, Value = "3"
                },
                BatchNumber = new Question {
                    Id = 4, Value = "4"
                },
                ReceiptDate = new Question {
                    Id = 5, Value = "5"
                },
                ShipDate = new Question {
                    Id = 6, Value = "6"
                },
                MedicationUsage = new List <RepeatableInventoryData> {
                    new RepeatableInventoryData {
                        Id       = 1,
                        DateUsed =
                            new Question
                        {
                            Id = 7, Value = "7"
                        },
                        QuantityUsed =
                            new Question
                        {
                            Id = 8, Value = "8"
                        }
                    }
                }
            };
            var repository = new InventoryFormDataRepository(dataStorage.Object);

            dataStorage.Setup(ds => ds.GetData <InventoryFormData>()).Returns(new List <InventoryFormData> {
                entity
            });
            //Act
            repository.Edit(updatedEntity);
            //Assert
            //Values are equal
            Assert.That(entity.QuantityShipped.Value, Is.EqualTo(updatedEntity.QuantityShipped.Value));
            Assert.That(entity.BatchNumber.Value, Is.EqualTo(updatedEntity.BatchNumber.Value));
            Assert.That(entity.ReceiptDate.Value, Is.EqualTo(updatedEntity.ReceiptDate.Value));
            Assert.That(entity.ShipDate.Value, Is.EqualTo(updatedEntity.ShipDate.Value));
            Assert.That(entity.MedicationUsage[0].DateUsed.Value, Is.EqualTo(updatedEntity.MedicationUsage[0].DateUsed.Value));
            Assert.That(entity.MedicationUsage[0].QuantityUsed.Value,
                        Is.EqualTo(updatedEntity.MedicationUsage[0].QuantityUsed.Value));

            //Objects are not equal
            Assert.That(entity.QuantityShipped, Is.Not.EqualTo(updatedEntity.QuantityShipped));
            Assert.That(entity.BatchNumber, Is.Not.EqualTo(updatedEntity.BatchNumber));
            Assert.That(entity.ReceiptDate, Is.Not.EqualTo(updatedEntity.ReceiptDate));
            Assert.That(entity.ShipDate, Is.Not.EqualTo(updatedEntity.ShipDate));
            Assert.That(entity.MedicationUsage[0].DateUsed, Is.Not.EqualTo(updatedEntity.MedicationUsage[0].DateUsed));
            Assert.That(entity.MedicationUsage[0].QuantityUsed, Is.Not.EqualTo(updatedEntity.MedicationUsage[0].QuantityUsed));
        }