<commit_before>﻿using FluentAssertions;
using Moq;
using NUnit.Framework;
using TddCourse.CustomerExample;

namespace TddCourse.Tests.Unit.Part15
{
    [TestFixture]
    public class CustomerRepositoryTests
    {
        [Test]
        public void WhenTryingToAddCustomerThatIsNotValidated_ThenCustomerIsNotAdded()
        {
            var customerValidatorMock = Mock.Of<ICustomerValidator>(validator => validator.Validate(It.IsAny<ICustomer>()) == false);

            var customerRepository = new CustomerRepository(customerValidatorMock);

            customerRepository.Add(It.IsAny<ICustomer>());

            customerRepository.AllCustomers.Should().BeEmpty();
        }

        [Test]
        public void WhenTryingToAddMultipleCustomers_ThenOnlyValidatedOnesAreAdded()
        { 
            var customerValidatorMock = Mock.Of<ICustomerValidator>(validator => validator.Validate(It.Is<ICustomer>(customer => customer.FirstName == "John")) == true);

            var customerRepository = new CustomerRepository(customerValidatorMock);

            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "John"));
            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "NotJohn"));

            customerRepository.AllCustomers.Should().HaveCount(1).And.OnlyContain(customer => customer.FirstName == "John");
        }

        [Test]
        public void WhenAddingCustomer_ThenValidateMethodOfValidatorIsCalledOnce()
        {
            var customerValidatorMock = new Mock<ICustomerValidator>();

            var customerRepository = new CustomerRepository(customerValidatorMock.Object);

            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "John"));

            customerValidatorMock.Verify(x => x.Validate(It.IsAny<ICustomer>()), Times.Exactly(2));
        }

        [Test]
        public void WhenAddingCustomer_ThenValidateMethodOfValidatorIsCalledOnce__Functional()
        {
            var customerValidatorMock = Mock.Of<ICustomerValidator>();

            var customerRepository = new CustomerRepository(customerValidatorMock);

            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "John"));

            Mock.Get(customerValidatorMock).Verify(validator => validator.Validate(It.Is<ICustomer>(customer => customer.FirstName == "John")), Times.Once);
        }
    }
}<commit_msg>Going back with the original value...<commit_after>﻿using FluentAssertions;
using Moq;
using NUnit.Framework;
using TddCourse.CustomerExample;

namespace TddCourse.Tests.Unit.Part15
{
    [TestFixture]
    public class CustomerRepositoryTests
    {
        [Test]
        public void WhenTryingToAddCustomerThatIsNotValidated_ThenCustomerIsNotAdded()
        {
            var customerValidatorMock = Mock.Of<ICustomerValidator>(validator => validator.Validate(It.IsAny<ICustomer>()) == false);

            var customerRepository = new CustomerRepository(customerValidatorMock);

            customerRepository.Add(It.IsAny<ICustomer>());

            customerRepository.AllCustomers.Should().BeEmpty();
        }

        [Test]
        public void WhenTryingToAddMultipleCustomers_ThenOnlyValidatedOnesAreAdded()
        { 
            var customerValidatorMock = Mock.Of<ICustomerValidator>(validator => validator.Validate(It.Is<ICustomer>(customer => customer.FirstName == "John")) == true);

            var customerRepository = new CustomerRepository(customerValidatorMock);

            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "John"));
            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "NotJohn"));

            customerRepository.AllCustomers.Should().HaveCount(1).And.OnlyContain(customer => customer.FirstName == "John");
        }

        [Test]
        public void WhenAddingCustomer_ThenValidateMethodOfValidatorIsCalledOnce()
        {
            var customerValidatorMock = new Mock<ICustomerValidator>();

            var customerRepository = new CustomerRepository(customerValidatorMock.Object);

            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "John"));

            customerValidatorMock.Verify(x => x.Validate(It.IsAny<ICustomer>()), Times.Once);
        }

        [Test]
        public void WhenAddingCustomer_ThenValidateMethodOfValidatorIsCalledOnce__Functional()
        {
            var customerValidatorMock = Mock.Of<ICustomerValidator>();

            var customerRepository = new CustomerRepository(customerValidatorMock);

            customerRepository.Add(Mock.Of<ICustomer>(customer => customer.FirstName == "John"));

            Mock.Get(customerValidatorMock).Verify(validator => validator.Validate(It.Is<ICustomer>(customer => customer.FirstName == "John")), Times.Once);
        }
    }
}
{'fraction_non_alphanumeric': 0.1077144029544522, 'fraction_numerical': 0.001436192039392696, 'mean_word_length': 3.4683776351970668, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4935462', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1235, 'n_words': 185}