public static ITestFixture StartServer2(this ITestFixture fixture) { var host2 = fixture.Get <IHost>(); try { host2.Start(); } catch (Exception exception) { throw new MiruTestConfigException( "Could not start host for the App. Check the Inner Exception and your Program.cs/Startup.cs configurations", exception.InnerException ?? exception); } // var server = fixture.Get<IServer>(); // // var addresses = server.Features.Get<IServerAddressesFeature>().Addresses; // // if (addresses.Count == 0) // throw new MiruTestConfigException( // "The App's Server has no http addresses associated to it. Maybe the App is already running in another process?"); return(fixture); }
/// <summary> /// Creates an auto fixture constructed instance of the specified model. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="model">The model.</param> /// <param name="composer">The composer.</param> /// <returns></returns> public static ITestFixture HavingComposedModel <TModel>(this ITestFixture fixture, out TModel model, Func <Faker, IPostprocessComposer <TModel>, IPostprocessComposer <TModel> > composer) { model = composer(fixture.Faker, fixture.AutoFixture.Build <TModel>()).Create(); return(fixture); }
protected AttributeTests(ITestFixture fixture, GlobalServiceProvider sp) : base(fixture, sp) { var fileInfo = GetFile(@"Tests\CodeModel\Support\AttributeInfo.cs"); classInfo = fileInfo.Classes.First(c => c.Name == nameof(AttributeTestClass)); }
/// <summary> /// Configures a mock of the specified type to setup a call matching the specified expression to return the specified result. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="expression">The expression.</param> /// <param name="result">The result.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMockedAsync <TService, TResult>( this ITestFixture fixture, Expression <Func <TService, Task <TResult> > > expression, TResult result, params Parameter[] parameters) where TService : class => fixture.HavingMock <TService>(m => m.Setup(expression).ReturnsAsync(result).Verifiable(), parameters);
/// <summary> /// Configures a mock of the specified type to setup a call matching the specified expression to throw the specified exception. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="expression">The expression.</param> /// <param name="exception">The exception.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMockThrow <TService>( this ITestFixture fixture, Expression <Action <TService> > expression, Exception exception, params Parameter[] parameters) where TService : class => fixture.HavingMock <TService>(m => m.Setup(expression).Throws(exception).Verifiable(), parameters);
/// <summary> /// Picks a random model from the specified collection. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="models">The models.</param> /// <param name="model">The model.</param> /// <returns></returns> public static ITestFixture HavingRandom <TModel>(this ITestFixture fixture, ICollection <TModel> models, out TModel model) { model = fixture.Faker.Random.CollectionItem(models); return(fixture); }
public static int EnqueuedCount(this ITestFixture fixture) { return(fixture.Get <JobStorage>() .GetMonitoringApi() .EnqueuedJobs("default", 0, 1000) .Count); }
public Test_SimpleComposedFixture(ComposedFixture fixture) { this.fixture = fixture; fixture.Start( () => { fixture.AddFixture("zero", fixture0 = new Fixture0(), subFixture => { fixture0Initialized = true; }); fixture.AddFixture("one", fixture1 = new Fixture1(), subFixture => { fixture1Initialized = true; }); // Ensure that the subfixtures were initialized first // and that their actions were called. Covenant.Assert(fixture0Initialized); Covenant.Assert(fixture1Initialized); // Ensure that the subfixture indexers work. Covenant.Assert(fixture[0] == fixture0); Covenant.Assert(fixture[1] == fixture1); Covenant.Assert(fixture["zero"] == fixture0); Covenant.Assert(fixture["one"] == fixture1); }); }
/// <summary> /// Creates a collection of auto fixture constructed instances of the specified model. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="models">The models.</param> /// <param name="composer">The composer.</param> /// <returns></returns> public static ITestFixture HavingComposedModels <TModel>(this ITestFixture fixture, out ICollection <TModel> models, Func <Faker, IPostprocessComposer <TModel>, IPostprocessComposer <TModel> > composer) { models = composer(fixture.Faker, fixture.AutoFixture.Build <TModel>()).CreateMany().ToList(); return(fixture); }
public static void LoginAs <TUser>(this ITestFixture fixture, TUser user) where TUser : UserfyUser { MiruTest.Log.Information($"Login as #{user.Id}-{user.Display}"); using var scope = fixture.App.WithScope(); TestingCurrentUser.User = user; }
public static async Task <TResult> ShouldAuthorizeAnonymous <TResult>( this ITestFixture fixture, IRequest <TResult> message) { fixture.Logout(); return(await fixture.App.SendAsync(message)); }
public static async Task ShouldNotAuthorizeAnonymous <TResult>( this ITestFixture fixture, IRequest <TResult> message) { fixture.Logout(); await Should.ThrowAsync <UnauthorizedException>(async() => await fixture.App.SendAsync(message)); }
public static IEnumerable <TJob> EnqueuedJobs <TJob>(this ITestFixture fixture) where TJob : IMiruJob => fixture.Get <JobStorage>() .GetMonitoringApi() .EnqueuedJobs("default", 0, 1000) .Select(result => result.Value) .Where(enqueueJob => enqueueJob.Job.Args[0].GetType() == typeof(TJob)) .Select(enqueueJob => (TJob)enqueueJob.Job.Args[0]) .ToList();
public Test(ITestFixture baseFixture, ITestFixture testFixture, string testMethod) { Reflector = new Reflector.Implementations.Reflector(); InstantiatedTestFixture = testFixture; InstantiatedBaseTestFixture = baseFixture; TestMethod = Reflector.GetMethodInfo(testMethod, InstantiatedTestFixture.Instance); StopWatch = new Stopwatch(); }
protected TestBase(ITestFixture fixture) { this.dte = fixture.Dte; this.metadataProvider = fixture.Provider; this.isRoslyn = fixture is RoslynFixture; this.isCodeDom = fixture is CodeDomFixture; }
public static void Logout(this ITestFixture fixture) { MiruTest.Log.Information("Logging out the current user"); using var scope = fixture.App.WithScope(); scope.Get <IUserSession>().LogoutAsync().GetAwaiter().GetResult(); }
protected TestBase(ITestFixture fixture) { this.dte = fixture.Dte; this.metadataProvider = fixture.Provider; this.isRoslyn = fixture is RoslynFixture; this.isCodeDom = fixture is CodeDomFixture; }
/// <summary> /// Configures a mock of the specified type to setup a call matching the /// specified expression to throw an exception of the specified type. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <typeparam name="TException">The type of the exception.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="expression">The expression.</param> /// <param name="composer">The composer.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMockThrow <TService, TException>( this ITestFixture fixture, Expression <Action <TService> > expression, Func <IPostprocessComposer <TException>, IPostprocessComposer <TException> > composer = null, params Parameter[] parameters) where TService : class where TException : Exception => fixture.HavingMockThrow(expression, out _, composer, parameters);
public bool Contains(ITestFixture testFixture) { foreach (var criterion in _criteria) { if (criterion.Contains(testFixture)) { return true; } } return false; }
public static bool EnqueuedOneJobFor <TJob>(this ITestFixture fixture) where TJob : IMiruJob { return(fixture.Get <JobStorage>() .GetMonitoringApi() .EnqueuedJobs("default", 0, 1000) .Select(result => result.Value) .Count(enqueueJob => enqueueJob.Job.Args[0].GetType() == typeof(TJob)) == 1); }
public static T MakeSaving <T>(this ITestFixture fixture, Action <T> customizations = null) where T : class { var entity = fixture.Make(customizations); fixture.Save(entity); return(entity); }
public ITestCase[] CreateTests(ITestFixture fixture, MethodInfo method) { ArrayList tests = new ArrayList(); object fixtureObject = fixture.CreateInstance(); ITestCase testFixtureTearDown = new TestFixtureTearDownTestCase(fixture.Name, method, fixtureObject); tests.Add(testFixtureTearDown); return (ITestCase[])tests.ToArray(typeof(ITestCase)); }
/// <summary> /// Configures the mock breakfast item repository to return a relevant breakfast item /// when called with the specified breakfast item type. /// </summary> public static ITestFixture HavingBreakfastItem(this ITestFixture fixture, BreakfastItemType type, out BreakfastItem item) => fixture.HavingMockedAsync <IBreakfastItemRepository, BreakfastItem>(x => x.GetBreakfastItemAsync(type), out item, (f, m) => { m.Type = type; m.Name = type.ToString(); });
public static async Task SendEmailNowAsync <TMail>(this ITestFixture fixture, TMail mail) where TMail : Mailable { using (var scope = fixture.App.WithScope()) { var mailer = scope.Get <IMailer>(); await mailer.SendNowAsync(mail); } }
public static int EnqueuedCount(this ITestFixture fixture) { return(fixture.Get <JobStorage>() .As <MemoryStorage>() .Data .GetEnumeration <JobDto>() .Count()); }
public static bool EnqueuedOneJobFor <TJob>(this ITestFixture fixture) where TJob : IJob { return(fixture.Get <JobStorage>() .As <MemoryStorage>() .Data .GetEnumeration <JobDto>() .Count(job => job.InvocationData.Contains(typeof(TJob).FullName !)) == 1); }
public static ITestFixture ClearFabricator(this ITestFixture fixture) { MiruTest.Log.Information($"Running _.{nameof(ClearFabricator)}()"); fixture.Get <Fabricator>().Clear(); return(fixture); }
/// <summary> /// Creates an auto fixture constructed instance of the specified model. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="model">The model.</param> /// <param name="composer">The composer.</param> /// <returns></returns> public static ITestFixture HavingModel <TModel>(this ITestFixture fixture, out TModel model, Action <Faker, TModel> composer = null) { model = fixture.AutoFixture.Create <TModel>(); composer?.Invoke(fixture.Faker, model); return(fixture); }
public static ITestFixture MigrateDatabase(this ITestFixture fixture) { MiruTest.Log.Information($"Running _.{nameof(MigrateDatabase)}()"); fixture.Get <IDatabaseMigrator>().UpdateSchema(); return(fixture); }
public override ITestCase[] CreateTests(ITestFixture fixture, MethodInfo method) { ArrayList testList = new ArrayList(); ParameterInfo[] parameters = method.GetParameters(); // create the models DomainCollection domains = new DomainCollection(); Type[] parameterTypes = new Type[parameters.Length]; int index = 0; foreach (ParameterInfo parameter in parameters) { parameterTypes[index] = parameter.ParameterType; DomainCollection pdomains = new DomainCollection(); foreach (UsingBaseAttribute usingAttribute in parameter.GetCustomAttributes(typeof(UsingBaseAttribute), true)) { try { usingAttribute.GetDomains(pdomains, parameter, fixture); } catch (Exception ex) { throw new Exception("Failed while loading domains from parameter " + parameter.Name, ex); } } if (pdomains.Count == 0) { throw new Exception("Could not find domain for argument " + parameter.Name); } domains.Add(Domains.ToDomain(pdomains)); index++; } // we make a cartesian product of all those foreach (ITuple tuple in Products.Cartesian(domains)) { // create data domains DomainCollection tdomains = new DomainCollection(); for (int i = 0; i < tuple.Count; ++i) { IDomain dm = (IDomain)tuple[i]; tdomains.Add(dm); } // computing the pairwize product foreach (ITuple ptuple in GetProduct(tdomains)) { ITestCase test = new MethodTestCase(fixture.Name, method, ptuple.ToObjectArray()); testList.Add(test); } } return (ITestCase[])testList.ToArray(typeof(ITestCase)); }
public static async Task Save <T>(this ITestFixture fixture, IEnumerable <T> entities) where T : IEntity { using (var scope = fixture.App.WithScope()) { var db = scope.Get <IDataAccess>(); await db.PersistAsync(entities.Cast <object>().ToArray()); } }
public static async Task ShouldNotAuthorize <TResult, TUser>( this ITestFixture fixture, TUser user, IRequest <TResult> message) where TUser : UserfyUser { fixture.LoginAs(user); await Should.ThrowAsync <UnauthorizedException>(async() => await fixture.App.SendAsync(message)); }
public static TReturn WithDb <TDbContext, TReturn>(this ITestFixture fixture, Func <TDbContext, TReturn> func) { using (var scope = fixture.App.WithScope()) { var db = scope.Get <TDbContext>(); return(func(db)); } }
public static async Task <TResult> ShouldAuthorize <TResult, TUser>( this ITestFixture fixture, TUser user, IRequest <TResult> message) where TUser : UserfyUser { fixture.LoginAs(user); return(await fixture.App.SendAsync(message)); }
protected TestBase(ITestFixture fixture, GlobalServiceProvider sp) { //sp.Reset(); this.dte = fixture.Dte; this.metadataProvider = fixture.Provider; this.isRoslyn = fixture is RoslynFixture; this.isCodeDom = false; }
public bool Contains(ITestFixture testFixture) { var assemblyName = testFixture.AssemblyName; var fixtureFullName = testFixture.FullName; foreach (var element in _elements) { if (element.Matches(assemblyName, fixtureFullName, string.Empty)) { return true; } } return false; }
//public override void GetDomains(IDomainCollection domains, ParameterInfo parameter, object fixture) //{ // domains.Add(domain); //} public override ITestCase[] CreateTests(ITestFixture fixture, System.Reflection.MethodInfo method) { ITestCase[] tc = new ITestCase[this._intStepCount]; for (int intCount = this._intStepCount; intCount < this._intStepCount; intCount++) { Object[] obj = new Object[0]; obj[0] = intCount; MethodTestCase mtc = new MethodTestCase(fixture.Name, method, obj); tc[intCount] = mtc; } return tc; //return new ITestCase[] { new MethodTestCase(fixture.Name, method, this.args) }; }
public override ITestCase[] CreateTests(ITestFixture fixture, MethodInfo method) { if (!method.IsPublic) { return new ITestCase[] { new IgnoreTestCase(fixture.Name, method.Name, "Test methods must be public.") }; } if (method.GetParameters().Length > 0) { return new ITestCase[] { new IgnoreTestCase(fixture.Name, method.Name, "Test methods mustn't take parameters.") }; } if (method.ReturnType != typeof(void)) { return new ITestCase[] { new IgnoreTestCase(fixture.Name, method.Name, "Test methods must return void.") }; } return new ITestCase[] { new MethodTestCase(fixture.Name, method) }; }
private bool IsIncluded(ITestFixture testFixture) { if( _includedCategories.IsEmpty || (testFixture.Categories.IsEmpty && testFixture.InheritedCategories.IsEmpty) ) { return true; } var local = new Categories(); local.Add(testFixture.Categories); local.Add(testFixture.InheritedCategories); return local.Intersect(_includedCategories).Count > 0; }
public bool Contains(ITestFixture testFixture) { return testFixture.FullName.StartsWith(_namespaceName); }
public bool Contains(ITestFixture testFixture) { return _methodFullName.StartsWith(testFixture.FullName); }
public bool Includes(ITestFixture testFixture) { throw new Exception("The method or operation is not implemented."); }
protected TestBase(ITestFixture fixture) { this.dte = fixture.Dte; this.metadataProvider = fixture.Provider; }
private bool Excluded(ITestFixture testFixture) { if(_excludedCategories.IsEmpty) { return false; } var local = new Categories(); local.Add(testFixture.Categories); local.Add(testFixture.InheritedCategories); return local.Intersect(_excludedCategories).Count > 0; }
private bool IsFixtureConfigured(ITestFixture testFixture) { return IsTestConfigured(testFixture.AssemblyName, testFixture.FullName, string.Empty); }
public bool Contains(ITestFixture testFixture) { return _configuredItems.Count == 0 || IsFixtureConfigured(testFixture); }
public bool Contains(ITestFixture testFixture) { return Matches(testFixture.FullName); }
public override ITestCase[] CreateTests(ITestFixture fixture, MethodInfo method) { return new ITestCase[] { new MethodTestCase(fixture.Name, method, this.args) }; }
public bool Contains(ITestFixture testFixture) { return testFixture.InheritedCategories.Contains(_categoryName) || testFixture.Categories.Contains(_categoryName); }
public bool Contains(ITestFixture testFixture) { return true; }
public bool Contains(ITestFixture testFixture) { return !_criterion.Contains(testFixture); }
public bool Includes(ITestFixture testFixture) { return IsIncluded(testFixture) && !Excluded(testFixture); }
public bool Contains(ITestFixture testFixture) { HasBeenCalled = true; return true; }
bool ITestSpec.Includes(ITestFixture testFixture) { return runnerMonitor.IncludesTest(testFixture.FullName); }