public void SetDefaultSupplier_ThrowException_WhenSupplierIsNull()
        {
            //ARRANGE
            var Assistante = new MSAssistantRole(new Mock <IMSUnitOfWork>().Object);

            //ACT
            Assert.ThrowsException <ArgumentNullException>(() => Assistante.SetDefaultSupplier(null));
        }
        public void SetDefaultSupplier_ThrowException_WhenSupplierIDisDifferentOfZero()
        {
            //ARRANGE
            var Assistante       = new MSAssistantRole(new Mock <IMSUnitOfWork>().Object);
            var SupplierToUpdate = new SupplierTO {
                Id = 0, Name = "InexistantSupplier"
            };

            //ACT
            Assert.ThrowsException <Exception>(() => Assistante.SetDefaultSupplier(SupplierToUpdate));
        }
        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 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 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 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);
        }