コード例 #1
0
        public void ContainsEmptyViolationsByDefault()
        {
            var contractAnalyzer = new ContractAnalyzer();

            Assert.NotNull(contractAnalyzer.Violations);
            Assert.Empty(contractAnalyzer.Violations);
        }
コード例 #2
0
        public void ContainsEmptyViolationsWhenUserAgeIsEqual18YearsOld()
        {
            var mockFraudDetector = new Mock <IFraudDetector>();

            mockFraudDetector.Setup(f => f.IsFraudDetected(It.IsAny <Contract>())).Returns(false);
            var contractAnalyzer = new ContractAnalyzer(mockFraudDetector.Object);
            var user             = new User("FirstName", "LastName", DateTime.Today.AddYears(-18));
            var contract         = new Contract("ContractName", user);

            contractAnalyzer.Analyze(contract);

            Assert.Empty(contractAnalyzer.Violations);
        }
コード例 #3
0
        public void ContainsAFraudViolationWhenFraudIsDetected()
        {
            var mockFraudDetector = new Mock <IFraudDetector>();

            mockFraudDetector.Setup(f => f.IsFraudDetected(It.IsAny <Contract>())).Returns(true);
            var contractAnalyzer = new ContractAnalyzer(mockFraudDetector.Object);
            var user             = new User("FirstName", "LastName", DateTime.Today.AddYears(-21));
            var contract         = new Contract("ContractName", user);

            contractAnalyzer.Analyze(contract);

            Assert.NotEmpty(contractAnalyzer.Violations);
            Assert.NotEmpty(contractAnalyzer.Violations.OfType <FraudViolation>());
            Assert.Single(contractAnalyzer.Violations.OfType <FraudViolation>());
        }
コード例 #4
0
        public void ContainsOnlyViolationsOfTheLastAnalyzedContract()
        {
            var mockFraudDetector = new Mock <IFraudDetector>();

            mockFraudDetector.Setup(f => f.IsFraudDetected(It.IsAny <Contract>())).Returns(true);
            var contractAnalyzer = new ContractAnalyzer(mockFraudDetector.Object);
            var userUnder18      = new User("FirstName1", "LastName1", DateTime.Today.AddYears(-17));
            var contractOne      = new Contract("Contract1", userUnder18);
            var userOver18       = new User("FirstName2", "LastName2", DateTime.Today.AddYears(-21));
            var contractTwo      = new Contract("Contract2", userOver18);

            contractAnalyzer.Analyze(contractOne);
            contractAnalyzer.Analyze(contractTwo);

            Assert.NotEmpty(contractAnalyzer.Violations);
            Assert.NotEmpty(contractAnalyzer.Violations.OfType <FraudViolation>());
            Assert.Single(contractAnalyzer.Violations.OfType <FraudViolation>());
            Assert.Empty(contractAnalyzer.Violations.OfType <UnderAgeViolation>());
        }
コード例 #5
0
        public void BeNotNull()
        {
            var contractAnalyzer = new ContractAnalyzer();

            Assert.NotNull(contractAnalyzer);
        }