Пример #1
0
        public GivenCustomerController()
        {
            var fixture = new Fixture();

            var mapperFactory      = new AutoMapperFactory();
            var customerRepository = Substitute.For <ICustomerRepository>(); //maybe forse a dictionary implementation instead of an inline mock


            _notExistingId = Guid.Empty;
            var customer = DomainGenerator.CustomerGenerator().Generate();

            _existingId = customer.Id;

            Dictionary <Guid, Customer> repo = new Dictionary <Guid, Customer>();

            repo.Add(_notExistingId, null);
            repo.Add(_existingId, customer);


            customerRepository.Get(Guid.Empty).Returns(null as Customer);
            customerRepository.Get(customer.Id).Returns(repo[customer.Id]);
            customerRepository
            .When(cr => cr.UpdateAsync(Arg.Any <Customer>()))
            .Do(callInfo =>
            {
                var callInfoCustomer = callInfo.Arg <Customer>();
                if (callInfoCustomer.Id == Guid.Empty)
                {
                    while (!repo.TryAdd(callInfoCustomer.Id, callInfoCustomer))
                    {
                        callInfoCustomer.Id = new Faker().Random.Guid();
                    }
                }
                else
                {
                    if (repo.ContainsKey(callInfoCustomer.Id))
                    {
                        repo[callInfoCustomer.Id] = callInfoCustomer;
                    }
                    else
                    {
                        throw new ArgumentException("Couldnt update repo, wasn't added");
                    }
                }
            });

            IErrorService errorService = new ErrorService();

            fixture.Inject(customerRepository);
            fixture.Inject(errorService);
            fixture.Customize(new AutoNSubstituteCustomization()
            {
                ConfigureMembers = true, GenerateDelegates = true
            });
            fixture.Inject(mapperFactory.CreateMapper <CustomerItem, Customer>()); //Is tested in other class, so used for easyness at the moment
            fixture.Inject(mapperFactory.CreateMapper <ContactInfoItem, ContactInfo>());
            fixture.Inject(new ControllerContext());
            _sut = fixture.Create <CustomerController>();
        }
        public async Task WhenWeAskToUpdateACustomer_ShouldBeAskedToUpsertInCosmosDB()
        {
            var newCustomer = DomainGenerator.CustomerGenerator().Generate();

            var updatedCustomer = await _sut.UpdateAsync(newCustomer);

            await _genericRepo.Received().UpdateAsync(Arg.Is <string>(newCustomer.Id.ToString()), Arg.Any <Customer>());
        }
        public async Task WhenWeAskToAddACustomer_ShouldBeAskedToStoreInCosmosDB()
        {
            var newCustomer = DomainGenerator.CustomerGenerator().Generate();

            var updatedCustomer = await _sut.AddAsync(newCustomer);

            await _genericRepo.Received().CreateAsync(Arg.Any <Customer>());
        }
Пример #4
0
        public void WhenMap_CustomerDto_Customer_ShouldAllPropertiesMapped()
        {
            var faker = new Faker();


            var entity = DomainGenerator.CustomerGenerator().Generate();

            var item = _sut.Map(entity);

            using (new AssertionScope())
            {
                entity.Id.Should().Be(item.Id);
                entity.FirstName.Should().Be(item.FirstName);
                entity.LastName.Should().Be(item.LastName);
            }
        }