public CustomizeTypeIgnoreTests() { domainGenerator = new DomainGenerator() .With <Product>(g => g.Ignore(e => e.Id)) .With <Category>(g => g.Ignore(e => e.Id)); }
public ComponentsTests() { domainGenerator = new DomainGenerator() .Component<SomeComponent>() .With(42); }
protected override void Act() { thing = new DomainGenerator() .With(true) .One(type); }
public ExplicitOneToOneTests() { domainGenerator = new DomainGenerator() .OneToOne <SomethingToGenerate, SomethingElseToGenerate>((l, r) => l.MyMethod(r)); }
public void paging_through_collection() { var suppliers = Session.QueryOver <Supplier>().List(); var productWith20Sources = new DomainGenerator() .With <ProductSource>(options => options.Ignore(productsource => productsource.Id)) .ForEach <ProductSource>(productsource => Session.Save(productsource)) .With <Product>(options => options.Ignore(product => product.Id)) .With <Product>(options => options.Ignore(product => product.Version)) .With <Product>(options => options.For(product => product.Category, ProductCategory.Beverages)) .With <Product>(g => g.Method <double>(20, 20, (product, d) => product.AddSource(suppliers.PickOne(), d))) .With <Product>(options => options.For(product => product.Name, new StringGenerator(1, 50))) .ForEach <Product>(product => Session.Save(product)) .One <Product>(); FlushAndClear(); var retrievedProduct = Session.Get <Product>(productWith20Sources.Id); var numberOfSources = Session.CreateQuery("select size(p.Sources) from Product p where p.Id = :productId") .SetParameter("productId", retrievedProduct.Id) .UniqueResult <int>(); const int pageSize = 5; var pages = numberOfSources % pageSize == 0 ? numberOfSources / pageSize : numberOfSources / pageSize + 1; for (int currentPageIndex = 0; currentPageIndex < pages; currentPageIndex++) { Logger.Info(string.Format("retrieving page {0}", currentPageIndex + 1)); Session.CreateFilter(retrievedProduct.Sources, "") .SetFirstResult(currentPageIndex * pageSize) .SetMaxResults(pageSize) .List <ProductSource>(); } }
public void PossibleValue() { var generator = new DomainGenerator() .With<SomethingToGenerate>(opt => opt.Construct(42)); Assert.Equal(42, generator.One<SomethingToGenerate>().CheckInt()); }
public static string GenerateEmail() { var gender = (GenderEnum)(_random.Next(1000) % 2 == 0 ? 0 : 1); var name = NameGenerator.GenerateFirstName(gender); var surname = NameGenerator.GenerateLastName(); var special1 = _randomSpecial[_random.Next(_randomSpecial.Length)].ToString(); var special2 = _randomSpecial[_random.Next(_randomSpecial.Length)].ToString(); var domain = DomainGenerator.GenerateDomain("@mail."); var dateYear = _random.Next(1950, 2018).ToString(); var randPath = _random.Next(4); switch (randPath) { case 0: return($"{name}{special1}{surname}{domain}".ToLower()); case 1: return($"{surname}{special1}{name}{special2}{dateYear}{domain}".ToLower()); case 2: return($"{name}{special1}{surname}{dateYear}{domain}".ToLower()); case 3: return($"{surname}{special2}{special1}{dateYear}{domain}".ToLower()); default: throw new ArgumentOutOfRangeException(); } }
public void Demonstrating() { var repository = new DomainGenerator().With(0, 42).With<SomethingtoGenerate>(); var something = new SomethingtoGenerate {MyProperty = 0}; repository.ModifyThis(something).Change(s => s.MyProperty); 5.Times(() => Assert.Equal(42, something.MyProperty)); }
public RelationsUsingTheModelBug() { domainGenerator = new DomainGenerator() .OneToMany <GrandFather, Father>(1, (f, c) => f.Add(c)) .OneToMany <Father, Child>(2, (f, c) => f.Add(c)); }
public CustomizeTypeSpecificStringLengthTests() { domainGenerator = new DomainGenerator() .With <SomethingToGenerate>(g => g.Length(e => e.MyProperty, 5)) .With <SomethingToGenerate>(g => g.Length(e => e.MyOtherProperty, 3, 10)); }
public ComponentsTests() { domainGenerator = new DomainGenerator() .Component <SomeComponent>() .With(42); }
public CustomizeTypeActionOneParameterMethodTests() { domainGenerator = new DomainGenerator() .With <SomethingToGenerate>(g => g.Method <int>((e, i) => e.MyMethod(i))) .With(42); }
public MultipleOneToManiesTests() { domainGenerator = new DomainGenerator() .OneToMany <SomeParent, SomeChild>(1, (one, many) => one.Children.Add(many)) .OneToMany <SomeParent, SomeOtherChild>(1, (one, many) => one.OtherChildren.Add(many)); }
public ForEachNullReferenceBug() { domainGenerator = new DomainGenerator() .OneToOne <SomethingToGenerate, SomethingElseToGenerate>((l, r) => l.MyMethod(r)) .ForEach <SomethingToGenerate>(s => s.SomethingElse.DoSomething()); }
public ModifyTests() { domainGenerator = new DomainGenerator() .Ignore(mi => mi.Name == "Id") .With <SomethingToGenerate>(g => g.For(e => e.MyProperty, 42, 43)); }
public CustomizeTypeActionOneParameterMethodTests() { domainGenerator = new DomainGenerator() .With<SomethingToGenerate>(g => g.Method<int>((e, i) => e.MyMethod(i))) .With(42); }
public CustomizeTypeActionTwoParameterMethod_MultipleTimes_Tests() { domainGenerator = new DomainGenerator() .With<SomethingToGenerate>(g => g.Method<int, int>(3, (e, i1, i2) => e.MyMethod(i1, i2))) .With(42); }
public ModifyTests() { domainGenerator = new DomainGenerator() .Ignore(mi => mi.Name == "Id") .With<SomethingToGenerate>(g => g.For(e => e.MyProperty, 42, 43)); }
public void paging_through_collection() { var suppliers = Session.QueryOver<Supplier>().List(); var productWith20Sources = new DomainGenerator() .With<ProductSource>(options => options.Ignore(productsource => productsource.Id)) .ForEach<ProductSource>(productsource => Session.Save(productsource)) .With<Product>(options => options.Ignore(product => product.Id)) .With<Product>(options => options.Ignore(product => product.Version)) .With<Product>(options => options.For(product => product.Category, ProductCategory.Beverages)) .With<Product>(g => g.Method<double>(20 , 20, (product, d) => product.AddSource(suppliers.PickOne(), d))) .With<Product>(options => options.For(product => product.Name, new StringGenerator(1, 50))) .ForEach<Product>(product => Session.Save(product)) .One<Product>(); FlushAndClear(); var retrievedProduct = Session.Get<Product>(productWith20Sources.Id); var numberOfSources = Session.CreateQuery("select size(p.Sources) from Product p where p.Id = :productId") .SetParameter("productId", retrievedProduct.Id) .UniqueResult<int>(); const int pageSize = 5; var pages = numberOfSources % pageSize == 0 ? numberOfSources / pageSize : numberOfSources / pageSize + 1; for (int currentPageIndex = 0; currentPageIndex < pages; currentPageIndex++) { Logger.Info(string.Format("retrieving page {0}", currentPageIndex + 1)); Session.CreateFilter(retrievedProduct.Sources, "") .SetFirstResult(currentPageIndex * pageSize) .SetMaxResults(pageSize) .List<ProductSource>(); } }
public void Generator() { var generator = new DomainGenerator() .With<SomethingToGenerate>(opt => opt.Construct<int>(new IntGenerator(42, 42))); Assert.Equal(42, generator.One<SomethingToGenerate>().CheckInt()); }
public CustomizeTypeSpecificStringLengthTests() { domainGenerator = new DomainGenerator() .With<SomethingToGenerate>(g => g.Length(e => e.MyProperty, 5)) .With<SomethingToGenerate>(g => g.Length(e => e.MyOtherProperty, 3, 10)); }
public CustomizeTypeActionTwoParameterMethod_MultipleTimes_Tests() { domainGenerator = new DomainGenerator() .With <SomethingToGenerate>(g => g.Method <int, int>(3, (e, i1, i2) => e.MyMethod(i1, i2))) .With(42); }
public void UsesDefaultValue() { var generator = new DomainGenerator().With(() => new SomethingToGenerate(42)); Assert.Equal(42, generator.One <SomethingToGenerate>().GetInt()); }
/// <summary> /// The get act selection of probe destination. /// </summary> /// <param name="filter"> /// The filter. /// </param> /// <returns> /// The <see cref="IList"/>. /// </returns> /// <exception cref="NotImplementedException"> /// </exception> public IList <ActSelectionOfProbeDto> GetActSelectionOfProbeDestination(ActSelectionOfProbeFilter filter) { var result = new DomainGenerator() .Many <ActSelectionOfProbeDto>(10); return(new List <ActSelectionOfProbeDto>(result)); }
public IgnoreConventionTypedTests() { domainGenerator = new DomainGenerator() .Ignore <SomethingToGenerate, int>(something => something.Id) .Ignore <SomethingElseToGenerate, string>(somethingElse => somethingElse.Id); }
public ProcessRequestsState() { Generator = new DomainGenerator() .With(mi => mi.DeclaringType == typeof(string), new StringGenerator(1, 1)) .With(mi => mi.DeclaringType == typeof(int), new IntGenerator(0, 5)) .With <Request>(opt => opt.StartingValue( () => new Request[] { new FirstRequest(), new SecondRequest(), new ThirdRequest(), new FourthRequest(), new FifthRequest(), new SixthRequest(), new SeventhRequest(), new FirstCachedRequest(), new SecondCachedRequest() }.PickOne())) .With( new DescribedAction { Exception = null, Description = "Does nothing" }, new DescribedAction { Exception = new BusinessException(), Description = "Throws BusinessException" }, new DescribedAction { Exception = new SecurityException(), Description = "Throws SecurityException" }, new DescribedAction { Exception = new UnknownException(), Description = "Throws UnknownException" }, new DescribedAction { Exception = new AnotherUnknownException(), Description = "Throws AnotherUnknownException" }, new DescribedAction { Exception = new SubTypeOfBusinessException(), Description = "Throws a subtype of BusinessException" }, new DescribedAction { Exception = new SubTypeOfSecurityException(), Description = "Throws a subtype of SecurityException" }); IoC.Container = new Agatha.Unity.Container(); new ServiceLayerConfiguration(Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly(), IoC.Container) { BusinessExceptionType = typeof(BusinessException), SecurityExceptionType = typeof(SecurityException), CacheManagerImplementation = typeof(CacheManagerSpy) }.Initialize(); // i want to take advantage of the automatic initialization, so i'm just resolving the requestprocessor instead of creating it RequestProcessor = IoC.Container.Resolve <IRequestProcessor>(); // the cache manager is a singleton so i can just resolve it and it'll be the same one the request processor uses CacheManager = (CacheManagerSpy)IoC.Container.Resolve <ICacheManager>(); CacheManager.ExceptionsThrown = ExceptionsThrown; }
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 WhenWeAskToAddACustomer_ShouldBeAskedToStoreInCosmosDB() { var newCustomer = DomainGenerator.CustomerGenerator().Generate(); var updatedCustomer = await _sut.AddAsync(newCustomer); await _genericRepo.Received().CreateAsync(Arg.Any <Customer>()); }
public async Task WhenWeAskToAdd_ShouldBeAskedToStoreInCosmosDB() { var newEntity = DomainGenerator.InvoiceGenerator().Generate(); var updatedEntity = await _sut.AddAsync(newEntity); await _genericRepo.Received().CreateAsync(Arg.Any <Invoice>()); }
public async Task WhenWeAskToUpdate_ShouldBeAskedToUpsertInCosmosDB() { var newInvoice = DomainGenerator.InvoiceGenerator().Generate(); var updatedInvoice = await _sut.UpdateAsync(newInvoice); await _genericRepo.Received().UpdateAsync(Arg.Is <string>(newInvoice.Id.ToString()), Arg.Any <Invoice>()); }
public NestedOneToOneBug() { domainGenerator = new DomainGenerator() .OneToOne<Child, Sibling>((c, s) => c.Sideways = s) .OneToMany<GrandFather, Father>(1, (f, c) => f.Add(c)) .OneToMany<Father, Child>(2, (f, c) => f.Add(c)); }
public virtual IList <PassDto> GetPass(PassFilter filter) { var result = new DomainGenerator() .With <PassDto>(x => x.For(c => c.Rn, (long)0, val => val + 1)) .Many <PassDto>(10).ToList(); return(result); }
public ForEachOnOneToManyOrderTests() { domainGenerator = new DomainGenerator() .OneToMany<One, Two>(1, (one, many) => one.Children.Add(many)) .OneToMany<Two, Three>(1, (one, many) => one.Children.Add(many)) .ForEach<Base>(o => objects.Add(o)); }
public NestedOneToOneBug() { domainGenerator = new DomainGenerator() .OneToOne <Child, Sibling>((c, s) => c.Sideways = s) .OneToMany <GrandFather, Father>(1, (f, c) => f.Add(c)) .OneToMany <Father, Child>(2, (f, c) => f.Add(c)); }
public PermissionMaterialExtensionDto GetPermissionMaterialExtension(long rn) { var result = new DomainGenerator() .With <PermissionMaterialExtensionDto>(x => x.For(c => c.Rn, rn)) .One <PermissionMaterialExtensionDto>(); return(result); }
public void GenerateDomainTest() { for (var i = 0; i < 10000; i++) { var toTest = DomainGenerator.GenerateDomain("@"); Assert.Contains("@", toTest); } }
public void GeneratePageAdressTest() { for (var i = 0; i < 10000; i++) { var toTest = DomainGenerator.GeneratePageAdress(); Assert.Contains("www.ra", toTest); } }
public void GeneratorIsApplied() { var domainGenerator = new DomainGenerator() .ForPrimitive(new IntGenerator(42, 42)); Assert.Equal(42, domainGenerator.One<SomethingToGenerate>().Value); }
private static DomainGenerator WithAddress(DomainGenerator generator) { return generator .Component<Address>() .With<Address>(options => options.For(address => address.Street, new StringGenerator(1, 100))) .With<Address>(options => options.For(address => address.City, new StringGenerator(1, 100))) .With<Address>(options => options.For(address => address.Country, new StringGenerator(1, 100))); }
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 CustomizeTypeActionTwoParameterMethodTests() { domainGenerator = new DomainGenerator() .With<SomethingToGenerate>(g => g.Method<int, string>((e, i, s) => e.MyMethod(i, s))) .With("TEST") .With(42); }
public void GeneratorIsApplied() { var domainGenerator = new DomainGenerator(); //.With(mi => mi.Name == "Value", new IntGenerator(42, 42)); Assert.Equal(42, domainGenerator.One<SomethingToGenerate>().Value); }
public CustomizeTypeActionTwoParameterMethodTests() { domainGenerator = new DomainGenerator() .With <SomethingToGenerate>(g => g.Method <int, string>((e, i, s) => e.MyMethod(i, s))) .With("TEST") .With(42); }
public ForEachOnOneToManyOrderTests() { domainGenerator = new DomainGenerator() .OneToMany <One, Two>(1, (one, many) => one.Children.Add(many)) .OneToMany <Two, Three>(1, (one, many) => one.Children.Add(many)) .ForEach <Base>(o => objects.Add(o)); }
public void OneToOneShouldThrow() { var generator = new DomainGenerator() .OneToOne <Something, SomethingElse>((s, se) => s.MySomethingElse = se); Assert.Throws <RecursiveRelationDefinedException>(() => generator.One <Something>()); }
private static DomainGenerator WithAddress(DomainGenerator generator) { return(generator .Component <Address>() .With <Address>(options => options.For(address => address.Street, new StringGenerator(1, 100))) .With <Address>(options => options.For(address => address.City, new StringGenerator(1, 100))) .With <Address>(options => options.For(address => address.Country, new StringGenerator(1, 100)))); }
public void OneToOneShouldThrow() { var generator = new DomainGenerator() .OneToOne<Something, SomethingElse>((s, se) => s.MySomethingElse = se); Assert.Throws<RecursiveRelationDefinedException>(() => generator.One<Something>()); }
public static void Create(ISession session) { var customers = WithAddress(new DomainGenerator()) .With<Customer>(options => options.Ignore(customer => customer.Id)) .With<Customer>(options => options.For(customer => customer.Name, new StringGenerator(5, 100))) .With<Customer>(options => options.For(customer => customer.DiscountPercentage, new DoubleGenerator(0, 25))) .ForEach<Customer>(customer => session.Save(customer)) .Many<Customer>(20, 40) .ToArray(); var managers = EmployeeGenerator(session) .ForEach<Employee>(employee => session.Save(employee)) .Many<Employee>(2); var employees = EmployeeGenerator(session) .ForEach<Employee>(employee => Maybe.Do(() => managers.PickOne().AddSubordinate(employee))) .ForEach<Employee>(employee => session.Save(employee)) .Many<Employee>(20) .ToArray(); var suppliers = WithAddress(new DomainGenerator()) .With<Supplier>(options => options.Ignore(supplier => supplier.Id)) .With<Supplier>(options => options.For(Supplier => Supplier.Name, new StringGenerator(5, 25))) .With<Supplier>(options => options.For(supplier => supplier.Website, new StringGenerator(1, 100))) .Many<Supplier>(20) .ToArray(); var products = new DomainGenerator() .With<ProductSource>(options => options.Ignore(productsource => productsource.Id)) .ForEach<ProductSource>(productsource => session.Save(productsource)) .With<Product>(options => options.Ignore(product => product.Id)) .With<Product>(options => options.Ignore(product => product.Version)) .With<Product>(options => options.For( product => product.Category, ProductCategory.Beverages, ProductCategory.Condiments, ProductCategory.DairyProducts, ProductCategory.Produce)) .With<Product>(g => g.Method<double>(0, 5, (product, d) => product.AddSource(suppliers.PickOne(), d))) .With<Product>(options => options.For(product => product.Name, new StringGenerator(1, 50))) .ForEach<Product>(product => session.Save(product)) .Many<Product>(50) .ToArray(); WithAddress(new DomainGenerator()) .With<OrderItem>(options => options.Ignore(item => item.Id)) .With<OrderItem>(options => options.For(item => item.Product, products)) .With<Order>(options => options.Ignore(order => order.Id)) .OneToMany<Order, OrderItem>(1, 5, (order, item) => order.AddItem(item)) .With<Order>(options => options.For(order => order.Customer, customers)) .With<Order>(options => options.For(order => order.Employee, employees)) .OneToOne<Order, Address>((order, address) => order.DeliveryAddress = address) .ForEach<Order>(order => session.Save(order)) .Many<Order>(50); session.Flush(); }
public void Works() { var thing = new DomainGenerator() .Component<Something>() .One<Something>(); Assert.Null(thing.MySomething.MySomething); }
public void UnidirectionalOneToOne() { var generator = new DomainGenerator() .OneToOne<Something, SomethingElse>((l, r) => l.MySomethingElse = r); var notZero = false; 5.Times(() => notZero = notZero || generator.One<Something>().MySomethingElse.Value != 0); Assert.True(notZero); }
public void GeneratorIsApplied() { var something = new DomainGenerator() .With((decimal)42) .One<SomethingToGenerate>(); Assert.Equal(42, something.Property); }
public void UsingDomainGenerator() { var generator = new DomainGenerator(); 100.Times(() => { var something = generator.One<SomethingToGenerate>(); Assert.NotEqual(0, something.PropOne); Assert.NotEqual(0, something.PropTwo); }); }
public void TheDefaultConstructor() { var y = new SomethingDerived(); var thing = new DomainGenerator() .With<SomethingToGenerate>(o => o.Construct(y)) .One<SomethingToGenerate>(); Assert.NotNull(thing.GetValue()); }
public void Applied() { var thing = new DomainGenerator() .Component<One>() .Component<Two>() .Component<Three>() .One<Root>(); Assert.Null(thing.MyOne.MyTwo.MyThree.MyOne); }
public void Decimals() { var something = new DomainGenerator() .With<decimal>(val => Math.Round(val, 2)) .One<SomeThingToGenerate>(); Assert.Equal(Math.Round(something.Decimal, 2), something.Decimal); Assert.Equal(Math.Round(something.OtherDecimal, 2), something.OtherDecimal); }
public OneToManyUsingConstructorTests() { domainGenerator = new DomainGenerator() .With(42) .OneToMany<SomeParent, SomeChild>( 1, one => new SomeChild(one), (one, many) => one.Children.Add(many)); }
public void You_May_Pick_More_Than_One_Carefully() { 10.Times( () => { var ints = new DomainGenerator().Many<int>(0, 5); // 5 == 4, tschh Assert.Throws<BeingPicky.TheNumberOfElementsToPickMustBeSmallerThanTheNumberOfPossibleChoices>( () => ints.Pick(5)); }); }
public void SimpleAppend() { var domainGenerator = new DomainGenerator() .With<SomethingToGenerate>(g => g.Counter(e => e.MyProperty)); Assert.Equal(1, domainGenerator.One<SomethingToGenerate>().MyProperty); Assert.Equal(2, domainGenerator.One<SomethingToGenerate>().MyProperty); Assert.Equal(3, domainGenerator.One<SomethingToGenerate>().MyProperty); }
public void SupplyingStartingValueAndStep() { var domainGenerator = new DomainGenerator() .With<SomethingToGenerate>(g => g.Counter(e => e.MyProperty, 5, 2)); Assert.Equal(5, domainGenerator.One<SomethingToGenerate>().MyProperty); Assert.Equal(7, domainGenerator.One<SomethingToGenerate>().MyProperty); Assert.Equal(9, domainGenerator.One<SomethingToGenerate>().MyProperty); }
public CustomizeForEachTests() { spy = new Spy(); domainGenerator = new DomainGenerator() .OneToMany<Category, Product>(1, (l, r) => { l.Products.Add(r); r.MyCategory = l; }) .ForEach<IThing>(thing => spy.Check(thing)); }