Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 /// <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);
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
 /// <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);
Exemplo n.º 5
0
 /// <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);
Exemplo n.º 6
0
 /// <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);
 }
Exemplo n.º 8
0
        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);
            });
        }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
        public static async Task <TResult> ShouldAuthorizeAnonymous <TResult>(
            this ITestFixture fixture,
            IRequest <TResult> message)
        {
            fixture.Logout();

            return(await fixture.App.SendAsync(message));
        }
Exemplo n.º 12
0
        public static async Task ShouldNotAuthorizeAnonymous <TResult>(
            this ITestFixture fixture,
            IRequest <TResult> message)
        {
            fixture.Logout();

            await Should.ThrowAsync <UnauthorizedException>(async() => await fixture.App.SendAsync(message));
        }
Exemplo n.º 13
0
 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();
Exemplo n.º 14
0
 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();
 }
Exemplo n.º 15
0
        protected TestBase(ITestFixture fixture)
        {
            this.dte = fixture.Dte;
            this.metadataProvider = fixture.Provider;

            this.isRoslyn  = fixture is RoslynFixture;
            this.isCodeDom = fixture is CodeDomFixture;
        }
Exemplo n.º 16
0
        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();
        }
Exemplo n.º 17
0
        protected TestBase(ITestFixture fixture)
        {
            this.dte = fixture.Dte;
            this.metadataProvider = fixture.Provider;

            this.isRoslyn = fixture is RoslynFixture;
            this.isCodeDom = fixture is CodeDomFixture;
        }
Exemplo n.º 18
0
 /// <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);
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 21
0
        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));
 }
Exemplo n.º 23
0
 /// <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();
 });
Exemplo n.º 24
0
 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);
     }
 }
Exemplo n.º 25
0
 public static int EnqueuedCount(this ITestFixture fixture)
 {
     return(fixture.Get <JobStorage>()
            .As <MemoryStorage>()
            .Data
            .GetEnumeration <JobDto>()
            .Count());
 }
Exemplo n.º 26
0
 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);
 }
Exemplo n.º 27
0
        public static ITestFixture ClearFabricator(this ITestFixture fixture)
        {
            MiruTest.Log.Information($"Running _.{nameof(ClearFabricator)}()");

            fixture.Get <Fabricator>().Clear();

            return(fixture);
        }
Exemplo n.º 28
0
 /// <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);
 }
Exemplo n.º 29
0
        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));
        }
Exemplo n.º 31
0
        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());
            }
        }
Exemplo n.º 32
0
        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));
        }
Exemplo n.º 33
0
        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));
            }
        }
Exemplo n.º 34
0
        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));
        }
Exemplo n.º 35
0
        protected TestBase(ITestFixture fixture, GlobalServiceProvider sp)
        {
            //sp.Reset();
            this.dte = fixture.Dte;
            this.metadataProvider = fixture.Provider;

            this.isRoslyn  = fixture is RoslynFixture;
            this.isCodeDom = false;
        }
Exemplo n.º 36
0
      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;
      }
Exemplo n.º 37
0
        //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) };
        }
Exemplo n.º 38
0
        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) };
        }
Exemplo n.º 39
0
 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;
 }
Exemplo n.º 40
0
 public bool Contains(ITestFixture testFixture) {
    return testFixture.FullName.StartsWith(_namespaceName);
 }
Exemplo n.º 41
0
 public bool Contains(ITestFixture testFixture) {
    return _methodFullName.StartsWith(testFixture.FullName);
 }
Exemplo n.º 42
0
 public bool Includes(ITestFixture testFixture) {
    throw new Exception("The method or operation is not implemented.");
 }
Exemplo n.º 43
0
 protected TestBase(ITestFixture fixture)
 {
     this.dte = fixture.Dte;
     this.metadataProvider = fixture.Provider;
 }
Exemplo n.º 44
0
 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;
 }
Exemplo n.º 45
0
 private bool IsFixtureConfigured(ITestFixture testFixture) {
    return IsTestConfigured(testFixture.AssemblyName, testFixture.FullName, string.Empty);
 }
Exemplo n.º 46
0
 public bool Contains(ITestFixture testFixture) {
    return _configuredItems.Count == 0 || IsFixtureConfigured(testFixture);
 }
Exemplo n.º 47
0
 public bool Contains(ITestFixture testFixture) {
    return Matches(testFixture.FullName);
 }
Exemplo n.º 48
0
 public override ITestCase[] CreateTests(ITestFixture fixture, MethodInfo method)
 {
     return new ITestCase[] { new MethodTestCase(fixture.Name, method, this.args) };
 }
Exemplo n.º 49
0
 public bool Contains(ITestFixture testFixture) {
    return testFixture.InheritedCategories.Contains(_categoryName)
           || testFixture.Categories.Contains(_categoryName);
 }
Exemplo n.º 50
0
 public bool Contains(ITestFixture testFixture) {
    return true;
 }
Exemplo n.º 51
0
 public bool Contains(ITestFixture testFixture) {
    return !_criterion.Contains(testFixture);
 }
Exemplo n.º 52
0
 public bool Includes(ITestFixture testFixture) {
    return IsIncluded(testFixture) && !Excluded(testFixture);
 }
Exemplo n.º 53
0
 public bool Contains(ITestFixture testFixture) {
    HasBeenCalled = true;
    return true;
 }
Exemplo n.º 54
0
 bool ITestSpec.Includes(ITestFixture testFixture)
 {
     return runnerMonitor.IncludesTest(testFixture.FullName);
 }