当前位置: 首页>>代码示例>>C#>>正文


C# TestContext类代码示例

本文整理汇总了C#中TestContext的典型用法代码示例。如果您正苦于以下问题:C# TestContext类的具体用法?C# TestContext怎么用?C# TestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestContext类属于命名空间,在下文中一共展示了TestContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TakeScreenshot

            private void TakeScreenshot(TestContext testContext)
            {
                var filename = Path.GetFullPath(testContext.FullyQualifiedTestClassName + ".jpg");
                try
                {
                    var screenLeft = SystemInformation.VirtualScreen.Left;
                    var screenTop = SystemInformation.VirtualScreen.Top;
                    var screenWidth = SystemInformation.VirtualScreen.Width;
                    var screenHeight = SystemInformation.VirtualScreen.Height;

                    // Create a bitmap of the appropriate size to receive the screenshot.
                    using (var bmp = new Bitmap(screenWidth, screenHeight))
                    {
                        // Draw the screenshot into our bitmap.
                        using (var g = Graphics.FromImage(bmp))
                        {
                            g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
                        }

                        bmp.Save(filename, ImageFormat.Jpeg);
                    }
                    testContext.AddResultFile(filename);
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("An exception occured while trying to take screenshot:");
                    Logger.WriteLine(ex);
                }
            }
开发者ID:arnonax,项目名称:TestEssentials,代码行数:29,代码来源:TestBase.cs

示例2: Tag_NotEqual

        public void Tag_NotEqual()
        {
            var testCacheKey = Guid.NewGuid().ToString();

            TestContext.DeleteAll(x => x.Entity_Basics);
            TestContext.Insert(x => x.Entity_Basics, 1);

            using (var ctx = new TestContext())
            {
                // BEFORE
                var itemCountBefore = ctx.Entity_Basics.FromCache(testCacheKey).Count();
                var cacheCountBefore = QueryCacheHelper.GetCacheCount();

                TestContext.DeleteAll(x => x.Entity_Basics);

                // AFTER
                var itemCountAfter = ctx.Entity_Basics.FromCache(testCacheKey, Guid.NewGuid().ToString()).Count();
                var cacheCountAfter = QueryCacheHelper.GetCacheCount();

                // TEST: The item count are NOT equal (A new cache key is used, the query is materialized)
                Assert.AreNotEqual(itemCountBefore, itemCountAfter);
                Assert.AreEqual(0, itemCountAfter);

                // TEST: The cache count are NOT equal (A new cache key is used)
                Assert.AreEqual(cacheCountBefore + 1, cacheCountAfter);
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:27,代码来源:NotEqual.cs

示例3: Many_Executor

        public void Many_Executor()
        {
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right1s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right2s);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Lefts, 1).First();
                left.Right1s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right1s, 5);
                left.Right2s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right2s, 5);
                ctx.SaveChanges();
            }


            using (var ctx = new TestContext())
            {
                var item = ctx.Association_Multi_OneToMany_Lefts
                    .Include(left => left.Right1s, true)
                    .Include(left => left.Right2s, true)
                    .First();

                // TEST: context
                Assert.AreEqual(11, ctx.ChangeTracker.Entries().Count());
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:26,代码来源:Many_Executor.cs

示例4: BracketedIdentifierSimplificationTest

            public void BracketedIdentifierSimplificationTest()
            {
                var expected = [email protected]"#Region ""{FeaturesResources.Assembly} mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""
' mscorlib.v4_0_30319_17626.dll
#End Region
Imports System.Runtime
Imports System.Runtime.InteropServices

Namespace System
    <__DynamicallyInvokableAttribute> <AttributeUsage(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Enum Or AttributeTargets.Constructor Or AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Event Or AttributeTargets.Interface Or AttributeTargets.Delegate, Inherited:=False)> <ComVisible(True)>
    Public NotInheritable Class [|ObsoleteAttribute|]
        Inherits Attribute

        <__DynamicallyInvokableAttribute>
        Public Sub New()
        <__DynamicallyInvokableAttribute>
        Public Sub New(message As String)
        <__DynamicallyInvokableAttribute> <TargetedPatchingOptOut(""Performance critical to inline this type of method across NGen image boundaries"")>
        Public Sub New(message As String, [error] As Boolean)
        <__DynamicallyInvokableAttribute>
        Public ReadOnly Property IsError As Boolean
        <__DynamicallyInvokableAttribute>
        Public ReadOnly Property Message As String
    End Class
End Namespace";

                using (var context = new TestContext(LanguageNames.VisualBasic))
                {
                    context.GenerateAndVerifySource("System.ObsoleteAttribute", expected);
                }
            }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:31,代码来源:MetadataAsSourceTests.VisualBasic.cs

示例5: TestGetClusterMetrics

        public async Task TestGetClusterMetrics()
        {
            var ctx = new TestContext();
            var urlProvider = ctx.UrlProviderFake;
            var restReqExecutor = ctx.RestRequestExecutorFake;
            var anyUri = Enumerable.Repeat(new Uri("anyscheme://anypath"), 1);
            urlProvider.GetUrlAsync().Returns(Task.FromResult(anyUri));
            var anyClusterMetrics = new ClusterMetrics
            {
                ActiveNodes = 5,
                AllocatedMB = 1000,
                AllocatedVirtualCores = 10,
                AppsCompleted = 301
            };
            restReqExecutor.ExecuteAsync<ClusterMetrics>(
                Arg.Is<RestRequest>(
                    req =>
                        req.Resource == "ws/v1/cluster/metrics" && req.RootElement == "clusterMetrics" &&
                        req.Method == Method.GET),
                anyUri.First(),
                CancellationToken.None).Returns(Task.FromResult(anyClusterMetrics));

            var yarnClient = ctx.GetClient();
            ClusterMetrics actualClusterMetrics = await yarnClient.GetClusterMetricsAsync();

            Assert.Equal(anyClusterMetrics, actualClusterMetrics);
            var unused = urlProvider.Received(1).GetUrlAsync();
        }
开发者ID:beomyeol,项目名称:reef,代码行数:28,代码来源:YarnClientTests.cs

示例6: Tag_Expire

        public void Tag_Expire()
        {
            var testCacheKey = Guid.NewGuid().ToString();

            TestContext.DeleteAll(x => x.Entity_Basics);
            TestContext.Insert(x => x.Entity_Basics, 1);

            using (var ctx = new TestContext())
            {
                // BEFORE
                var itemCountBefore = ctx.Entity_Basics.FromCache(testCacheKey).Count();
                var cacheCountBefore = QueryCacheHelper.GetCacheCount();

                TestContext.DeleteAll(x => x.Entity_Basics);

                QueryCacheManager.ExpireTag(testCacheKey);
                var cacheCountExpired = QueryCacheHelper.GetCacheCount();

                // TEST: The cache count are NOT equal (The cache key has been removed)
                Assert.AreEqual(cacheCountBefore - 1, cacheCountExpired);

                // AFTER
                var itemCountAfter = ctx.Entity_Basics.FromCache(testCacheKey).Count();
                var cacheCountAfter = QueryCacheHelper.GetCacheCount();

                // TEST: The item count are NOT equal (The query has been expired)
                Assert.AreNotEqual(itemCountBefore, itemCountAfter);
                Assert.AreEqual(0, itemCountAfter);

                // TEST: The cache count are NOT equal (The expired cache key is added)
                Assert.AreEqual(cacheCountExpired + 1, cacheCountAfter);
                Assert.AreEqual(cacheCountBefore, cacheCountAfter);
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:34,代码来源:Expire.cs

示例7: Thirty

        public void Thirty()
        {
            TestContext.DeleteAll(x => x.Entity_Basics);
            TestContext.Insert(x => x.Entity_Basics, 50);

            using (var ctx = new TestContext())
            {
                // BEFORE
                Assert.AreEqual(1225, ctx.Entity_Basics.Sum(x => x.ColumnInt));

                // ACTION
                var clock = new Stopwatch();
                clock.Start();
                var rowsAffected = ctx.Entity_Basics.Where(x => x.ColumnInt > 10 && x.ColumnInt <= 40).Update(x => new Entity_Basic { ColumnInt = 99 }, update =>
                {
                    update.BatchDelayInterval = 50;
                    update.BatchSize = 5;
                });
                clock.Stop();

                // AFTER
                Assert.AreEqual(460, ctx.Entity_Basics.Sum(x => x.ColumnInt));
                Assert.AreEqual(30, rowsAffected);
                Assert.IsTrue(clock.ElapsedMilliseconds > 250 && clock.ElapsedMilliseconds < 600);
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:26,代码来源:FiftyMilliseconds.cs

示例8: IntializeAssembly

 public static void IntializeAssembly(TestContext ctx)
 {
     //   根据配置文件中的设置来设置
     // 测试数据库
     DatabaseTestClass.TestService.DeployDatabaseProject();
     DatabaseTestClass.TestService.GenerateData();
 }
开发者ID:huaminglee,项目名称:hfoa,代码行数:7,代码来源:DatabaseSetup.cs

示例9: GenerateAndVerifySource

 internal static void GenerateAndVerifySource(string metadataSource, string symbolName, string projectLanguage, string expected, bool compareTokens = true, bool includeXmlDocComments = false)
 {
     using (var context = new TestContext(projectLanguage, SpecializedCollections.SingletonEnumerable(metadataSource), includeXmlDocComments))
     {
         context.GenerateAndVerifySource(symbolName, expected, compareTokens);
     }
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:7,代码来源:AbstractMetadataAsSourceTests.cs

示例10: Single_Executor

        public void Single_Executor()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                ctx.SaveChanges();
            }


            using (var ctx = new TestContext())
            {
                var item = ctx.Association_OneToMany_Lefts.IncludeQuery(left => left.Rights.Where(x => x.ColumnInt > 2)).First();

                // TEST: context
                Assert.AreEqual(3, ctx.ChangeTracker.Entries().Count());

                // TEST: right
                Assert.AreEqual(2, item.Rights.Count);

                if (item.Rights[0].ColumnInt == 3)
                {
                    Assert.AreEqual(3, item.Rights[0].ColumnInt);
                    Assert.AreEqual(4, item.Rights[1].ColumnInt);
                }
                else
                {
                    Assert.AreEqual(4, item.Rights[0].ColumnInt);
                    Assert.AreEqual(3, item.Rights[1].ColumnInt);
                }
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:35,代码来源:Single_Executor.cs

示例11: Queryable_AsTracking

        public void Queryable_AsTracking()
        {
            TestContext.DeleteAll(x => x.Entity_Basics);
            TestContext.Insert(x => x.Entity_Basics, 10);

            using (var ctx = new TestContext())
            {
                // BEFORE
                var cacheCountBefore = QueryFutureManager.Cache.Count();

                var futureValue1 = ctx.Entity_Basics.Where(x => x.ColumnInt < 5).OrderBy(x => x.ColumnInt).FutureValue();
                var futureValue2 = ctx.Entity_Basics.Where(x => x.ColumnInt >= 5).OrderBy(x => x.ColumnInt).FutureValue();

                // TEST: The cache count are NOT equal (A new context has been added)
                Assert.AreEqual(cacheCountBefore + 1, QueryFutureManager.Cache.Count());

                var value = futureValue1.Value;

                // AFTER

                // TEST: The cache count are equal (The new context has been removed)
                Assert.AreEqual(cacheCountBefore, QueryFutureManager.Cache.Count());

                // TEST: The futureList1 has a value and the first item is returned
                Assert.IsTrue(futureValue1.HasValue);
                Assert.AreEqual(0, value.ColumnInt);

                // TEST: The futureList2 has a value and the first item is returned
                Assert.IsTrue(futureValue2.HasValue);
                Assert.AreEqual(5, futureValue2.Value.ColumnInt);

                // TEST: The first item of both FutureValue has been added
                Assert.AreEqual(2, ctx.ChangeTracker.Entries().Count());
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:35,代码来源:Queryable_AsTracking.cs

示例12: Test

		public Task Test (TestContext ctx, CancellationToken cancellationToken,
			InstrumentationConnectionProvider provider,
			GenericConnectionInstrumentParameters parameters,
			GenericConnectionInstrumentTestRunner runner)
		{
			return runner.Run (ctx, cancellationToken);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:7,代码来源:MartinTest.cs

示例13: Initialize

 public static void Initialize(TestContext context)
 {
     Connection.DisableServerCertValidation = true;
     // uncomment the following to write frame traces
     //Trace.TraceLevel = TraceLevel.Frame;
     //Trace.TraceListener = (f, a) => System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("[hh:ss.fff]") + " " + string.Format(f, a));
 }
开发者ID:Indifer,项目名称:amqpnetlite,代码行数:7,代码来源:LinkTests.cs

示例14: IncludeEntityAdded_IsFalse

        public void IncludeEntityAdded_IsFalse()
        {
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Basics);

            TestContext.Insert(x => x.Entity_Basics, 2);

            var audit = AuditHelper.AutoSaveAudit();
            audit.Configuration.IncludeEntityAdded = false;

            using (var ctx = new TestContext())
            {
                var list = ctx.Entity_Basics.OrderBy(x => x.ID).ToList();

                // INSERT one
                TestContext.Insert(ctx, x => x.Entity_Basics, 1);

                // DELETE one
                ctx.Entity_Basics.Remove(list[0]);

                // UPDATE one
                list[1].ColumnInt++;

                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(2, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityDeleted, entries[1].State);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).ToList();

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(2, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityDeleted, entries[1].State);
                    }
                }
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:60,代码来源:IncludeEntityAdded_IsFalse.cs

示例15: RestClientGetRequestReturnsResponse

        public async Task RestClientGetRequestReturnsResponse()
        {
            var tc = new TestContext();

            var client = tc.GetRestClient();

            var anyRequest = new RestRequest
            {
                Method = Method.GET,
                Resource = AnyResource,
                RootElement = AnyRootElement
            };

            var successfulResponseMessage = CreateSuccessfulResponseMessage();
            tc.HttpClient.GetAsync(AnyRequestUri + anyRequest.Resource, CancellationToken.None)
                .Returns(Task.FromResult(successfulResponseMessage));

            var response =
                await client.ExecuteRequestAsync<AnyResponse>(anyRequest, AnyRequestUri, CancellationToken.None);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(AnyStringField, response.Data.AnyStringField);
            Assert.Equal(AnyIntField, response.Data.AnyIntField);
            Assert.Null(response.Exception);
            var unused = tc.HttpClient.Received(1).GetAsync(AnyRequestUri + anyRequest.Resource, CancellationToken.None);
        }
开发者ID:beomyeol,项目名称:reef,代码行数:26,代码来源:RestClientTests.cs


注:本文中的TestContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。