public object Create(object request, ISpecimenContext context) { if (!(request is SeededRequest seededRequest)) { return(_builder.Create(request, context)); } var currentDepth = -1; var requestsForCurrentThread = GetMonitoredRequestsForCurrentThread(); if (requestsForCurrentThread.Count > 0) { currentDepth = requestsForCurrentThread.Max(x => x.Depth) + 1; } var depthRequest = new DepthSeededRequest(seededRequest.Request, seededRequest.Seed, currentDepth); if (depthRequest.Depth >= _generationDepth) { return(new OmitSpecimen()); } requestsForCurrentThread.Push(depthRequest); try { return(_builder.Create(seededRequest, context)); } finally { requestsForCurrentThread.Pop(); } }
private static MeasurementConditionData CreateMeasurementConditionData(ISpecimenBuilder fixture) { if (fixture.Create <bool>()) { return(fixture.Create <IceCoveredData>()); } return(fixture.Create <OpenWaterData>()); }
public override void Verify(PropertyInfo property) { if (property is null) { throw new ArgumentNullException(nameof(property)); } object notifyPropObj = builder.Create(property.DeclaringType); if (!(notifyPropObj is INotifyPropertyChanged notifyProp)) { throw new ArgumentException($"The provided property must belong to a type implementing the '{typeof(INotifyPropertyChanged)}' interface"); } bool raised = false; try { notifyProp.PropertyChanged += OnPropertyChanged; object newPropValue = builder.Create(property); property.SetValue(notifyProp, newPropValue); if (!raised) { string errorMsg = PropertyChangedDidNotRaise(property); throw new PropertyChangedException(errorMsg); } } finally { notifyProp.PropertyChanged -= OnPropertyChanged; } void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (raised) { string errorMsg = PropertyChangedRaisedMultipleEvents(property); throw new PropertyChangedException(errorMsg); } if (e.PropertyName != property.Name) { string errorMsg = PropertyChangedRaisedWithWrongName(property, e.PropertyName); throw new PropertyChangedException(errorMsg); } raised = true; } }
/// <summary> /// Invokes the supplied function with anonymous parameter values and /// returns the result. /// </summary> /// <typeparam name="T1"> /// The type of the first anonymous parameter. /// </typeparam> /// <typeparam name="T2"> /// The type of the second anonymous parameter. /// </typeparam> /// <typeparam name="TResult">The return type.</typeparam> /// <param name="builder">The builder.</param> /// <param name="function">The function to invoke.</param> /// <returns>The return value of <paramref name="function"/>.</returns> /// <exception cref="System.ArgumentNullException"> /// builder is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// function is null /// </exception> public static TResult Get <T1, T2, TResult>( this ISpecimenBuilder builder, Func <T1, T2, TResult> function) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (function == null) { throw new ArgumentNullException(nameof(function)); } return(function(builder.Create <T1>(), builder.Create <T2>())); }
/// <summary> /// Invokes the supplied action with anonymous parameter values. /// </summary> public static void Do <T1, T2>( this ISpecimenBuilder builder, Action <T1, T2> action) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } action(builder.Create <T1>(), builder.Create <T2>()); }
public async Task <Match> RegistrateMatchAsync( ISpecimenBuilder fixture, Team homeTeam, Team awayTeam) { var team1 = await _teamTestsHelper.AddAsync(homeTeam); var team2 = await _teamTestsHelper.AddAsync(awayTeam); var currentMatch = new Match { Id = Guid.NewGuid(), AwayTeamId = team2.Id, HomeTeamId = team1.Id, Start = fixture.Create <DateTime>(), }; await _fixture.ExecuteDbContextAsync(async dbContext => { await dbContext.Matches.AddAsync(currentMatch); await dbContext.SaveChangesAsync(); }); return(currentMatch); }
public object Create(object request, ISpecimenContext context) { if (context == null) { using (InstanceGetters.DisableProcessing()) throw new ArgumentNullException("context"); } var result = m_builder.Create(request, context); using (InstanceGetters.DisableProcessing()) { if (!(result is NoSpecimen)) { return(result); } var requestedType = request as Type; if (requestedType == null) { return(new NoSpecimen()); } { if (requestedType == typeof(IntPtr)) { return(IntPtr.Zero); } } return(new NoSpecimen()); } }
public static DateTime CreateMongoDbDate(this ISpecimenBuilder builder) { var date = builder.Create <DateTime>(); // Cut precision to milliseconds return(date.AddTicks(-(date.Ticks % 10000))); }
private static DbContextOptions <FigureMathDbContext> CreateFigureMathDbContextOptions(ISpecimenBuilder fixture) { return(new DbContextOptionsBuilder <FigureMathDbContext>() .UseInMemoryDatabase(fixture.Create <string>()) .ConfigureWarnings(options => options.Ignore(InMemoryEventId.TransactionIgnoredWarning)) .Options); }
private static int PrepareBinPacking(ISpecimenBuilder fixture) { var bins = fixture.CreateMany <int>(10000).ToList(); var c = fixture.Create <int>(); const int n = 100; return(BestFitBinPacking.Resolve(bins, n, c)); }
public ShouldSavePersonWithCategories(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder) { var categories = specimenBuilder.CreateMany<CategoryField>(_count).ToList(); var fake = specimenBuilder.Create<Person>(); var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.SanMarcos, categories); session.SaveOrUpdate(person); _personId = person.Id; }
public ShouldSavePersonWithLinks(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder) { var links = specimenBuilder.CreateMany<LinkField>(_count).ToList(); var fake = specimenBuilder.Create<Person>(); var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.Georgetown, null, links); session.SaveOrUpdate(person); _personId = person.Id; }
public ShouldSaveApproval(ISession session, ISpecimenBuilder fixture) { var person = fixture.Create<Person>(); session.SaveOrUpdate(person); var approval = new Approval { Person = person }; session.SaveOrUpdate(approval); _approvalId = approval.Id; }
public object Create(object request, ISpecimenContext context) { if (request is ParameterInfo param) { return(wrapped.Create(new SeededRequest(param.ParameterType, param.Name), context)); } return(new NoSpecimen()); }
public ShouldSavePersonWithLinksRemoved(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder, IContainer container) { _container = container; var links = specimenBuilder.CreateMany<LinkField>(_startCount).ToList(); var fake = specimenBuilder.Create<Person>(); var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.SanMarcos, null, links); session.SaveOrUpdate(person); _personId = person.Id; }
private static BaseElement GetBaseElement(ISpecimenBuilder fixture) { var fake = new Mock <BaseElement>(); fake.Setup(f => f.ToString(It.IsAny <bool>(), It.IsAny <int>())) .Returns(fixture.Create <string>()); return(fake.Object); }
public ShouldSavePersonWithLinks(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder) { var links = specimenBuilder.CreateMany <LinkField>(_count).ToList(); var fake = specimenBuilder.Create <Person>(); var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.Georgetown, null, links); session.SaveOrUpdate(person); _personId = person.Id; }
public ShouldSavePersonWithCategories(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder) { var categories = specimenBuilder.CreateMany <CategoryField>(_count).ToList(); var fake = specimenBuilder.Create <Person>(); var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.SanMarcos, categories); session.SaveOrUpdate(person); _personId = person.Id; }
private static TimeUnitModel CreateTimeUnitModel(ISpecimenBuilder fixture) { var timeUnit = fixture.Create <TimeUnit>(); return(new TimeUnitModel { Description = timeUnit.Description(), Name = timeUnit.Name(), }); }
public ShouldSavePersonWithLinksRemoved(ISession session, PersonFactory personFactory, ISpecimenBuilder specimenBuilder, IContainer container) { _container = container; var links = specimenBuilder.CreateMany <LinkField>(_startCount).ToList(); var fake = specimenBuilder.Create <Person>(); var person = personFactory.CreatePerson(fake.Name, fake.Email, fake.Bio, Location.SanMarcos, null, links); session.SaveOrUpdate(person); _personId = person.Id; }
/// <summary> /// Invokes the supplied action with anonymous parameter values. /// </summary> /// <typeparam name="T1"> /// The type of the first anonymous parameter. /// </typeparam> /// <typeparam name="T2"> /// The type of the second anonymous parameter. /// </typeparam> /// <typeparam name="T3"> /// The type of the third anonymous parameter. /// </typeparam> /// <typeparam name="T4"> /// The type of the fourth anonymous parameter. /// </typeparam> /// <param name="builder">The builder.</param> /// <param name="action">The action to invoke.</param> /// <exception cref="System.ArgumentNullException"> /// builder is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// action is null /// </exception> public static void Do <T1, T2, T3, T4>( this ISpecimenBuilder builder, Action <T1, T2, T3, T4> action) { if (builder == null) { throw new ArgumentNullException("builder"); } if (action == null) { throw new ArgumentNullException("action"); } action( builder.Create <T1>(), builder.Create <T2>(), builder.Create <T3>(), builder.Create <T4>()); }
public object Create(object request, ISpecimenContext context) { dynamic s = _builder.Create(request, context); if (s is NoSpecimen) { return(s); } s.SetupAllProperties(); return(s); }
public ShouldSaveApproval(ISession session, ISpecimenBuilder fixture) { var person = fixture.Create <Person>(); session.SaveOrUpdate(person); var approval = new Approval { Person = person }; session.SaveOrUpdate(approval); _approvalId = approval.Id; }
public object Create(object request, ISpecimenContext context) { var result = _innerRandomDateTimeSequenceGenerator.Create(request, context); if (result is NoSpecimen) { return(result); } return(((DateTime)result).ToUniversalTime()); }
private static Order CreateOrder(ISpecimenBuilder fixture) { var callOffId = fixture.Create <CallOffId>(); var order = new Order { CallOffId = callOffId, Revision = callOffId.Revision, }; BackingField.SetValue(order, nameof(Order.Id), callOffId.Id); return(order); }
/// <summary> /// Invokes the supplied function with an anonymous parameter value and /// returns the result. /// </summary> /// <typeparam name="T"> /// The type of the anonymous parameter. /// </typeparam> /// <typeparam name="TResult">The return type.</typeparam> /// <param name="builder">The builder.</param> /// <param name="function">The function to invoke.</param> /// <returns>The return value of <paramref name="function"/>.</returns> /// <exception cref="System.ArgumentNullException"> /// builder is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// function is null /// </exception> public static TResult Get <T, TResult>( this ISpecimenBuilder builder, Func <T, TResult> function) { if (builder == null) { throw new ArgumentNullException("builder"); } if (function == null) { throw new ArgumentNullException("function"); } return(function(builder.Create <T>())); }
public static WebModset CreateTestModset( ISpecimenBuilder fixture, string?modsDirectory = null, int eachModTypeNumber = 5) { var modset = new WebModset { Mods = new List <WebMod>(), Dlcs = new List <WebDlc>(), LastUpdatedAt = fixture.Create <DateTime>(), Name = fixture.Create <string>(), Id = fixture.Create <string>() }; for (var i = 0; i < eachModTypeNumber; i++) { modset.Mods.Add(CreateTestMod(fixture, WebModType.ServerSide, modsDirectory)); modset.Mods.Add(CreateTestMod(fixture, WebModType.ClientSide, modsDirectory)); modset.Mods.Add(CreateTestMod(fixture, WebModType.Optional, modsDirectory)); modset.Mods.Add(CreateTestMod(fixture, WebModType.Required, modsDirectory)); } return(modset); }
public object Create(object request, ISpecimenContext context) { object s = _builder.Create(request, context); if (s is NoSpecimen) { return(s); } // var mock = (Mock)s; // var objectSpace = context.Resolve(typeof(IObjectSpace)); // var mockType = mock.GetType().GetGenericArguments().Single(); // if (typeof(ITestData).IsAssignableFrom(mockType)) // SetupProperties(mock, context); return(s); }
public void ShouldCreateAsManyDistinctInstancesAsCtorParameters( [Substitute] ISpecimenBuilder specimenBuilder) { specimenBuilder.Create(Arg.Any <object>(), Arg.Any <ISpecimenContext>()).Returns(1); var sut = new ConstructorArgumentsTracker(specimenBuilder, typeof(SimpleType).GetConstructors().Single()); var instance = sut.CreateNewInstance() as SimpleType; specimenBuilder.ClearReceivedCalls(); var instances = sut.CreateDistinctInstancesByChaningOneByOneCtorArgIn(instance).ToList(); specimenBuilder.Received(1).Create(Arg.Is(typeof(int)), Arg.Any <ISpecimenContext>()); Assert.Equal(1, instances.Count); }
/// <summary> /// Danner en liste indeholdende modeller for konti. /// </summary> /// <returns>Liste indeholdende modeller for konti.</returns> private static IEnumerable <IKontoModel> GetKontoModels(ISpecimenBuilder fixture, IEnumerable <IKontogruppeViewModel> kontogrupper, Random random, int count) { if (fixture == null) { throw new ArgumentNullException("fixture"); } if (kontogrupper == null) { throw new ArgumentNullException("kontogrupper"); } if (random == null) { throw new ArgumentNullException("random"); } var kontogruppeArray = kontogrupper.ToArray(); var result = new List <IKontoModel>(count); while (result.Count < count) { var kontoModelMock = MockRepository.GenerateMock <IKontoModel>(); kontoModelMock.Expect(m => m.Kontonummer) .Return(fixture.Create <string>()) .Repeat.Any(); kontoModelMock.Expect(m => m.Kontonavn) .Return(fixture.Create <string>()) .Repeat.Any(); kontoModelMock.Expect(m => m.Beskrivelse) .Return(fixture.Create <string>()) .Repeat.Any(); kontoModelMock.Expect(m => m.Notat) .Return(fixture.Create <string>()) .Repeat.Any(); kontoModelMock.Expect(m => m.Kontogruppe) .Return(kontogruppeArray.Length == 0 ? -1 : kontogruppeArray.ElementAt(random.Next(kontogruppeArray.Length - 1)).Nummer) .Repeat.Any(); kontoModelMock.Expect(m => m.StatusDato) .Return(fixture.Create <DateTime>()) .Repeat.Any(); kontoModelMock.Expect(m => m.Kredit) .Return(fixture.Create <decimal>()) .Repeat.Any(); kontoModelMock.Expect(m => m.Saldo) .Return(fixture.Create <decimal>()) .Repeat.Any(); result.Add(kontoModelMock); } return(result); }
private static Mock <IFileSystem> CreateAndSetupFileSystemMock( ISpecimenBuilder fixture, DownloadJob.JobId newDownloadId) { var fileSystemMock = fixture.Create <Mock <IFileSystem> >(); fileSystemMock .SetupGet(fs => fs.FileStream.Create($"/incomplete/{newDownloadId}", FileMode.CreateNew).CanWrite) .Returns(true); fileSystemMock /* Simulate saveAsFile.iso already existing to test name incrementing logic */ .Setup(fs => fs.File.Move( $"/incomplete/{newDownloadId}", "/completed/saveAsFile.iso", false)) .Throws <IOException>(); return(fileSystemMock); }
public object Create(object request, ISpecimenContext context) { if (request == null) { throw new ArgumentNullException("request"); } if (context == null) { throw new ArgumentNullException("context"); } if (requestFilter.IsSatisfiedBy(request)) { var constructor = GetConstructor(request); return(constructor.Invoke(GetConstructorParameters(constructor, context).ToArray())); } return(builder.Create(request, context)); }
public object Create(object request, ISpecimenContext context) { if (context == null) { using (InstanceGetters.DisableProcessing()) throw new ArgumentNullException("context"); } var result = m_builder.Create(request, context); var specimen = default(PrigTypeSpecimen); if ((specimen = result as PrigTypeSpecimen) != null) { return(CreateMock(specimen, context)); } else if (!(result is NoSpecimen)) { return(result); } using (InstanceGetters.DisableProcessing()) return(new NoSpecimen()); }
private static Mock <DelegatingHandler> CreateAndSetupDownloadHttpClientStub( ISpecimenBuilder fixture) { var downloadResponse = new HttpResponseMessage { Content = new StringContent("file contents") }; downloadResponse.Content.Headers.Add("Content-Length", 42.ToString()); var httpClientStub = fixture.Create <Mock <DelegatingHandler> >(); httpClientStub .Protected() .As <IProtectedDelegatingHandler>() .Setup(h => h.SendAsync( It.Is <HttpRequestMessage>(r => r.Method == HttpMethod.Get && r.RequestUri !.OriginalString == "https://download.stuff/file.iso"), It.IsAny <CancellationToken>())) .ReturnsAsync(downloadResponse); return(httpClientStub); }