public void GetMenu_ReturnMealsInEnglish_WhenEnglishLanguageIsProvided() { //ARRANGE var SupplierToUse = new SupplierTO() { Id = 33, Name = "MockedSupplier" }; var fakeMealRepo = new Mock <IMealRepository>(); fakeMealRepo.Setup(x => x.GetMealsBySupplier(It.IsAny <SupplierTO>())).Returns(TestHelper.GetTestsListOfMeals()); var fakeSupplierRepo = new Mock <ISupplierRepository>(); fakeSupplierRepo.Setup(x => x.GetDefaultSupplier()).Returns(SupplierToUse); var unitOfWorkMock = new Mock <IMSUnitOfWork>(); unitOfWorkMock.Setup(x => x.MealRepository).Returns(fakeMealRepo.Object); unitOfWorkMock.Setup(x => x.SupplierRepository).Returns(fakeSupplierRepo.Object); //ACT var participant = new MSAttendeeRole(unitOfWorkMock.Object); var listMenu = participant.GetMenu(); //ASSERT Assert.AreEqual("BrieEN", listMenu.Skip(0).First().ToDomain().ToString(Language.English)); Assert.AreEqual("ClubEN", listMenu.Skip(1).First().ToDomain().ToString(Language.English)); Assert.AreEqual("PestoEN", listMenu.Skip(2).First().ToDomain().ToString(Language.English)); Assert.AreEqual("Brie* - Honey - Nuts*", listMenu.Skip(0).First().ToDomain().GetIngredientsString(Language.English)); Assert.AreEqual("Ham - Butter - Salad - Cheese*", listMenu.Skip(1).First().ToDomain().GetIngredientsString(Language.English)); Assert.AreEqual("Pesto - Arugula - Eggs*", listMenu.Skip(2).First().ToDomain().GetIngredientsString(Language.English)); }
public List <MealTO> GetMealsBySupplier(SupplierTO Supplier) => mealContext.Meals .Include(x => x.Supplier) .Include(x => x.MealsComposition) .Where(x => x.Supplier.Id == Supplier.Id) .Select(x => x.ToTranfertsObject()) .ToList();
public void GetMenu_ReturnMealsInFrench_WhenFrenchLanguageIsProvided() { //ARRANGE var SupplierToUse = new SupplierTO() { Id = 33, Name = "MockedSupplier" }; var fakeMealRepo = new Mock <IMealRepository>(); fakeMealRepo.Setup(x => x.GetMealsBySupplier(It.IsAny <SupplierTO>())).Returns(TestHelper.GetTestsListOfMeals()); var fakeSupplierRepo = new Mock <ISupplierRepository>(); fakeSupplierRepo.Setup(x => x.GetDefaultSupplier()).Returns(SupplierToUse); var unitOfWorkMock = new Mock <IMSUnitOfWork>(); unitOfWorkMock.Setup(x => x.MealRepository).Returns(fakeMealRepo.Object); unitOfWorkMock.Setup(x => x.SupplierRepository).Returns(fakeSupplierRepo.Object); //ACT var participant = new MSAttendeeRole(unitOfWorkMock.Object); var listMenu = participant.GetMenu(); //ASSERT Assert.AreEqual("BrieFR", listMenu.Skip(0).First().ToDomain().ToString(Language.French)); Assert.AreEqual("ClubFR", listMenu.Skip(1).First().ToDomain().ToString(Language.French)); Assert.AreEqual("PestoFR", listMenu.Skip(2).First().ToDomain().ToString(Language.French)); Assert.AreEqual("Brie* - Miel - Noix*", listMenu.Skip(0).First().ToDomain().GetIngredientsString(Language.French)); Assert.AreEqual("Jambon - Beurre - Salade - Fromage*", listMenu.Skip(1).First().ToDomain().GetIngredientsString(Language.French)); Assert.AreEqual("Pesto - Roquette - Oeufs*", listMenu.Skip(2).First().ToDomain().GetIngredientsString(Language.French)); }
public void GetMenu_ReturnMealsWithDutch_WhenDutchLanguageIsProvided() { //ARRANGE var SupplierToUse = new SupplierTO() { Id = 33, Name = "MockedSupplier" }; var fakeMealRepo = new Mock <IMealRepository>(); fakeMealRepo.Setup(x => x.GetMealsBySupplier(It.IsAny <SupplierTO>())).Returns(TestHelper.GetTestsListOfMeals()); var fakeSupplierRepo = new Mock <ISupplierRepository>(); fakeSupplierRepo.Setup(x => x.GetDefaultSupplier()).Returns(SupplierToUse); var unitOfWorkMock = new Mock <IMSUnitOfWork>(); unitOfWorkMock.Setup(x => x.MealRepository).Returns(fakeMealRepo.Object); unitOfWorkMock.Setup(x => x.SupplierRepository).Returns(fakeSupplierRepo.Object); //ACT var participant = new AttendeeRole(unitOfWorkMock.Object); var listMenu = participant.GetMenu(); //ASSERT Assert.AreEqual("BrieNL", listMenu.Skip(0).First().ToDomain().ToString(Language.Dutch)); Assert.AreEqual("ClubNL", listMenu.Skip(1).First().ToDomain().ToString(Language.Dutch)); Assert.AreEqual("PestoNL", listMenu.Skip(2).First().ToDomain().ToString(Language.Dutch)); Assert.AreEqual("Brie* - Honing - Noten*", listMenu.Skip(0).First().ToDomain().GetIngredientsString(Language.Dutch)); Assert.AreEqual("Ham - Boter - Salade - Kaas*", listMenu.Skip(1).First().ToDomain().GetIngredientsString(Language.Dutch)); Assert.AreEqual("Pesto - Rucola - Eien*", listMenu.Skip(2).First().ToDomain().GetIngredientsString(Language.Dutch)); }
public static SupplierEF ToEF(this SupplierTO Supplier) => new SupplierEF { Id = Supplier.Id, Name = Supplier.Name, IsDefault = Supplier.IsDefault };
public void SetDefaultSupplier(SupplierTO Supplier) { if (Supplier is null) { throw new ArgumentNullException(nameof(Supplier)); } if (Supplier.Id is default(int)) { throw new Exception("Invalid SupplierID"); } var SupplierToMakeCurrent = GetByID(Supplier.Id); SupplierToMakeCurrent.IsDefault = true; mealContext.Suppliers .UpdateRange( GetAll() .Select(x => { x.IsDefault = false; return(x.ToEF()); }) .ToArray() ); Update(SupplierToMakeCurrent); isDefaultSupplierUniquenessWithThrow("SetCurrentSupplier(SupplierTO) after update"); }
public bool AddSupplier(SupplierTO supplier) { if (supplier is null) { throw new ArgumentNullException(nameof(supplier)); } if (supplier.Id != 0) { throw new InvalidSupplierException(); } try { UnitOfWork.SupplierRepository.Insert(supplier.ToDomain().ToTO()); if (supplier.IsDefault) { UnitOfWork.SupplierRepository.SetDefaultSupplier(supplier.ToDomain().ToTO()); } return(true); } catch (InvalidSupplierException ex) { // Probably need better exception handling throw ex; } }
public bool SetDefaultSupplier(SupplierTO Supplier) { if (Supplier is null) { throw new ArgumentNullException(nameof(Supplier)); } if (Supplier.Id == 0) { throw new Exception("Inexisting supplier"); } if (!Supplier.IsDefault) { throw new Exception("Supplier not marked as current supplier."); } try { iMSUnitOfWork.SupplierRepository.SetDefaultSupplier(Supplier.ToDomain().ToTransfertObject()); return(true); } catch (Exception ex) { throw ex; } }
public void Test_AddSupplier_ReturnsTrueAndSetsDefault_WhenSupplierIsValidAndIsDefault() { // Arrange var supplier = new SupplierTO { Name = "Name", ContactName = "ContactName", Email = "Email", IsDefault = true }; var mockSupplierRepo = new Mock <ISupplierRepository>(); mockSupplierRepo.Setup(x => x.Insert(It.IsAny <SupplierTO>())); mockSupplierRepo.Setup(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>())); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(x => x.SupplierRepository).Returns(mockSupplierRepo.Object); var assistant = new Assistant(mockUnitOfWork.Object); // Act var result = assistant.AddSupplier(supplier); // Assert Assert.IsTrue(result); mockSupplierRepo.Verify(x => x.Insert(It.IsAny <SupplierTO>()), Times.Once); mockSupplierRepo.Verify(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>()), Times.Once); }
public void GetMenu_ReturnHasRightCountOfMeals_WhenAValidLanguageIsProvided() { //ARRANGE var SupplierToUse = new SupplierTO() { Id = 33, Name = "MockedSupplier" }; var fakeMealRepo = new Mock <IMealRepository>(); //fakeMealRepo.Setup(x => x.GetAll()).Returns(GetTestsListOfMeal()); fakeMealRepo.Setup(x => x.GetMealsBySupplier(It.IsAny <SupplierTO>())).Returns(TestHelper.GetTestsListOfMeals()); //var fakeIngredientRepo = new Mock<IRepository<IngredientTO, int>>(); var fakeSupplierRepo = new Mock <ISupplierRepository>(); fakeSupplierRepo.Setup(x => x.GetDefaultSupplier()).Returns(SupplierToUse); var unitOfWorkMock = new Mock <IMSUnitOfWork>(); unitOfWorkMock.Setup(x => x.MealRepository).Returns(fakeMealRepo.Object); unitOfWorkMock.Setup(x => x.SupplierRepository).Returns(fakeSupplierRepo.Object); //ACT var participant = new MSAttendeeRole(unitOfWorkMock.Object); var listMenu = participant.GetMenu(); //ASSERT Assert.AreEqual(3, listMenu.Count()); }
public bool AddSupplier(SupplierTO Supplier) { if (Supplier is null) { throw new ArgumentNullException(nameof(Supplier)); } if (Supplier.Id != 0) { throw new Exception("Existing supplier"); } try { iMSUnitOfWork.SupplierRepository.Add(Supplier.ToDomain().ToTransfertObject()); if (Supplier.IsDefault) { iMSUnitOfWork.SupplierRepository.SetDefaultSupplier(Supplier.ToDomain().ToTransfertObject()); } return(true); } //TODO Code to test Unique Constraint on Name... catch (Exception ex) { throw ex; } }
public void RemoveSupplier_ThrowException_WhenSupplierIDisZero() { //ARRANGE var Assistante = new MSAssistantRole(new Mock <IMSUnitOfWork>().Object); var SupplierToRemove = new SupplierTO { Id = 0, Name = "InexistantSupplier" }; //ACT Assert.ThrowsException <Exception>(() => Assistante.RemoveSupplier(SupplierToRemove)); }
public void UpdateSupplier_ThrowException_WhenSupplierIDisDifferentOfZero() { //ARRANGE var Assistante = new AssistantRole((new Mock <IMSUnitOfWork>()).Object); var SupplierToUpdate = new SupplierTO { Id = 0, Name = "InexistantSupplier" }; //ACT Assert.ThrowsException <Exception>(() => Assistante.UpdateSupplier(SupplierToUpdate)); }
public void AddSupplier_ThrowException_WhenSupplierIDisDiferentOfZero() { //ARRANGE var Assistante = new AssistantRole((new Mock <IMSUnitOfWork>()).Object); var SupplierToAdd = new SupplierTO { Id = 10, Name = "ExistantSupplier" }; //ACT Assert.ThrowsException <Exception>(() => Assistante.AddSupplier(SupplierToAdd)); //TODO TEST IF INSERT IS CALLED Times.None: mockSupplierRepository.Verify(x => x.Insert(It.IsAny<SupplierTO>()), Times.Once); }
public void AddSupplier_ThrowIsNullOrWhiteSpaceException_WhenSupplierNameISEmptyString() { //ARRANGE var Assistante = new AssistantRole((new Mock <IMSUnitOfWork>()).Object); var SupplierToAdd = new SupplierTO { Id = 0, Name = "" }; //ACT Assert.ThrowsException <IsNullOrWhiteSpaceException>(() => Assistante.AddSupplier(SupplierToAdd)); //TODO TEST IF INSERT IS CALLED Times.None: mockSupplierRepository.Verify(x => x.Insert(It.IsAny<SupplierTO>()), Times.Once); }
public bool Remove(SupplierTO Entity) { var mealRepository = new MealRepository(this.mealContext); if (mealRepository.GetMealsBySupplier(Entity).Any()) { throw new Exception("Cannot delete supplier that has a meal in db."); } else { mealContext.Suppliers.Remove(Entity.ToEF()); return(true); } }
public static SupplierEF ToEF(this SupplierTO supplierTO) { if (supplierTO is null) { throw new ArgumentNullException(nameof(supplierTO)); } return(new SupplierEF { Id = supplierTO.Id, Name = supplierTO.Name, ContactName = supplierTO.ContactName, Email = supplierTO.Email, LanguageChoice = supplierTO.LanguageChoice, IsDefault = supplierTO.IsDefault }); }
public void SetDefaultSupplier_ReturnsFalse_WhenAValidSupplierWithIsDefaultFalseIsProvidedAndUpdatedInDB() { //ARRANGE var mockSupplierRepository = new Mock <ISupplierRepository>(); mockSupplierRepository.Setup(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>())); var mockUoW = new Mock <IMSUnitOfWork>(); mockUoW.Setup(x => x.SupplierRepository).Returns(mockSupplierRepository.Object); var Assistante = new MSAssistantRole(mockUoW.Object); var SupplierToUpdate = new SupplierTO { Id = 10, Name = "ExistantSupplier", IsDefault = false }; //ACT Assert.ThrowsException <Exception>(() => Assistante.SetDefaultSupplier(SupplierToUpdate)); }
public void Test_AddSupplier_ThrowsException_WhenSupplierIsNull() { // Arrange SupplierTO badSupplier = null; var mockSupplierRepo = new Mock <ISupplierRepository>(); mockSupplierRepo.Setup(x => x.Insert(It.IsAny <SupplierTO>())); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(x => x.SupplierRepository).Returns(mockSupplierRepo.Object); var assistant = new Assistant(new Mock <IUnitOfWork>().Object); // Assert Assert.ThrowsException <ArgumentNullException>(() => assistant.AddSupplier(badSupplier)); mockSupplierRepo.Verify(x => x.Insert(It.IsAny <SupplierTO>()), Times.Never); }
public static Supplier ToDomain(this SupplierTO SupplierTO) { try { var SupplierDomain = new Supplier() { Id = SupplierTO.Id, Name = SupplierTO.Name, IsCurrentSupplier = SupplierTO.IsDefault }; SupplierDomain.IsValid(); return(SupplierDomain); } catch (Exception ex) { throw ex; } }
public void AddSupplier_SupplierRepositoryIsCalledOnce_WhenAValidSupplierIsProvidedAndAddToDB() { //ARRANGE var mockSupplierRepository = new Mock <ISupplierRepository>(); mockSupplierRepository.Setup(x => x.Add(It.IsAny <SupplierTO>())); var mockUoW = new Mock <IMSUnitOfWork>(); mockUoW.Setup(x => x.SupplierRepository).Returns(mockSupplierRepository.Object); var Assistante = new AssistantRole(mockUoW.Object); var SupplierToAdd = new SupplierTO { Id = 0, Name = "InexistantSupplier" }; //ACT Assistante.AddSupplier(SupplierToAdd); mockSupplierRepository.Verify(x => x.Add(It.IsAny <SupplierTO>()), Times.Once); }
public void AddSupplier_ReturnsTrue_WhenAValidSupplierIsProvidedAndAddToDB() { //ARRANGE var mockSupplierRepository = new Mock <ISupplierRepository>(); mockSupplierRepository.Setup(x => x.Add(It.IsAny <SupplierTO>())); var mockUoW = new Mock <IMSUnitOfWork>(); mockUoW.Setup(x => x.SupplierRepository).Returns(mockSupplierRepository.Object); var Assistante = new AssistantRole(mockUoW.Object); var SupplierToAdd = new SupplierTO { Id = 0, Name = "InexistantSupplier" }; //ACT var ReturnValueToAssert = Assistante.AddSupplier(SupplierToAdd); Assert.IsTrue(ReturnValueToAssert); }
public void Test_AddSupplier_ThrowsException_WhenSupplierIdIsNotZero() { // Arrange var badSupplier = new SupplierTO { Id = 10 }; var mockSupplierRepo = new Mock <ISupplierRepository>(); mockSupplierRepo.Setup(x => x.Insert(It.IsAny <SupplierTO>())); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(x => x.SupplierRepository).Returns(mockSupplierRepo.Object); var assistant = new Assistant(new Mock <IUnitOfWork>().Object); // Assert Assert.ThrowsException <InvalidSupplierException>(() => assistant.AddSupplier(badSupplier)); mockSupplierRepo.Verify(x => x.Insert(It.IsAny <SupplierTO>()), Times.Never); }
public void SetDefaultSupplier_ReturnsTrue_WhenAValidSupplierWithIsDefaultTrueIsProvidedAndUpdatedInDB() { //ARRANGE var mockSupplierRepository = new Mock <ISupplierRepository>(); mockSupplierRepository.Setup(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>())); var mockUoW = new Mock <IMSUnitOfWork>(); mockUoW.Setup(x => x.SupplierRepository).Returns(mockSupplierRepository.Object); var Assistante = new MSAssistantRole(mockUoW.Object); var SupplierToUpdate = new SupplierTO { Id = 10, Name = "ExistantSupplier", IsDefault = true }; //ACT var ReturnValueToAssert = Assistante.SetDefaultSupplier(SupplierToUpdate); Assert.IsTrue(ReturnValueToAssert); }
public void UpdateSupplier_SupplierRepositoryIsCalledOnce_WhenAValidSupplierWithIsDefaultTrueIsProvidedAndUpdatedInDB() { //ARRANGE var mockSupplierRepository = new Mock <ISupplierRepository>(); mockSupplierRepository.Setup(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>())); var mockUoW = new Mock <IMSUnitOfWork>(); mockUoW.Setup(x => x.SupplierRepository).Returns(mockSupplierRepository.Object); var Assistante = new MSAssistantRole(mockUoW.Object); var SupplierToUpdate = new SupplierTO { Id = 10, Name = "ExistantSupplier", IsDefault = true }; //ACT Assistante.SetDefaultSupplier(SupplierToUpdate); mockSupplierRepository.Verify(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>()), Times.Once); }
public static Supplier ToDomain(this SupplierTO supplierTO) { if (supplierTO is null) { throw new ArgumentNullException(nameof(supplierTO)); } var supplier = new Supplier { Id = supplierTO.Id, Name = supplierTO.Name, ContactName = supplierTO.ContactName, Email = supplierTO.Email, LanguageChoice = supplierTO.LanguageChoice, IsDefault = supplierTO.IsDefault }; supplier.CheckValidity(); return supplier; }
public void SetDefaultSupplier_ThrowsException_WhenAInvalidSupplierWithIsDefaultTrueIsProvidedAndUpdatedInDB() { //ARRANGE var mockSupplierRepository = new Mock <ISupplierRepository>(); mockSupplierRepository.Setup(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>())); var mockUoW = new Mock <IMSUnitOfWork>(); mockUoW.Setup(x => x.SupplierRepository).Returns(mockSupplierRepository.Object); var Assistante = new MSAssistantRole(mockUoW.Object); var SupplierToUpdate = new SupplierTO { Id = 10, Name = "", IsDefault = true }; //ACT //Assert.ThrowsException<Exception>(()=> try { Assistante.SetDefaultSupplier(SupplierToUpdate); } catch { } mockSupplierRepository.Verify(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>()), Times.Never); }
public bool RemoveSupplier(SupplierTO Supplier) { try { if (Supplier is null) { throw new ArgumentNullException(nameof(Supplier)); } if (Supplier.Id == 0) { throw new Exception("Supplier not in DB."); } iMSUnitOfWork.SupplierRepository.Remove(Supplier.ToDomain().ToTransfertObject()); return(true); } catch (Exception ex) { throw ex; } }
public void Test_AddSupplier_ThrowsException_WhenSupplierContactNameIsInvalid() { // Arrange var badSupplier1 = new SupplierTO { Name = "Name", ContactName = null, Email = "Email" }; var badSupplier2 = new SupplierTO { Name = "Name", ContactName = "", Email = "Email" }; var badSupplier3 = new SupplierTO { Name = "Name", ContactName = " ", Email = "Email" }; var badSupplier4 = new SupplierTO { Name = "Name", ContactName = "\t", Email = "Email" }; var badSupplier5 = new SupplierTO { Name = "Name", ContactName = "\n \t ", Email = "Email" }; var mockSupplierRepo = new Mock <ISupplierRepository>(); mockSupplierRepo.Setup(x => x.Insert(It.IsAny <SupplierTO>())); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(x => x.SupplierRepository).Returns(mockSupplierRepo.Object); var assistant = new Assistant(new Mock <IUnitOfWork>().Object); // Assert Assert.ThrowsException <InvalidSupplierException>(() => assistant.AddSupplier(badSupplier1)); Assert.ThrowsException <InvalidSupplierException>(() => assistant.AddSupplier(badSupplier2)); Assert.ThrowsException <InvalidSupplierException>(() => assistant.AddSupplier(badSupplier3)); Assert.ThrowsException <InvalidSupplierException>(() => assistant.AddSupplier(badSupplier4)); Assert.ThrowsException <InvalidSupplierException>(() => assistant.AddSupplier(badSupplier5)); mockSupplierRepo.Verify(x => x.Insert(It.IsAny <SupplierTO>()), Times.Never); }
public void AddSupplier_ReturnsTrueAndSetsDefault_WhenAValidSupplierIsProvidedWithIsDefaultAndAddToDB() { //ARRANGE var mockSupplierRepository = new Mock <ISupplierRepository>(); mockSupplierRepository.Setup(x => x.Add(It.IsAny <SupplierTO>())); mockSupplierRepository.Setup(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>())); var mockUoW = new Mock <IMSUnitOfWork>(); mockUoW.Setup(x => x.SupplierRepository).Returns(mockSupplierRepository.Object); var Assistante = new MSAssistantRole(mockUoW.Object); var SupplierToAdd = new SupplierTO { Id = 0, Name = "InexistantSupplier", IsDefault = true }; //ACT var ReturnValueToAssert = Assistante.AddSupplier(SupplierToAdd); Assert.IsTrue(ReturnValueToAssert); mockSupplierRepository.Verify(x => x.Add(It.IsAny <SupplierTO>()), Times.Once); mockSupplierRepository.Verify(x => x.SetDefaultSupplier(It.IsAny <SupplierTO>()), Times.Once); }