private IUnitTestElement GetOrCreateAndUpdateElement( ITestEntity testEntity, Func <ITestIdentity, ITestElement> factory) { var elementId = _unitTestElementIdFactory.Create(_testProvider, testEntity.Project, testEntity.Identity.Absolute); var identity = new TestIdentity(elementId, testEntity.Identity); var element = _unitTestElementManager.GetElementByIdentity(identity) ?? factory(identity); element.Update(testEntity.Text, explicitReason: null, categories: testEntity.Categories.Select(x => _unitTestElementCategoryFactory.Create(x))); return(element); }
private bool FindCertificate(byte[] certificate, out TestIdentity identity, out TestCertificate testCertificate) { identity = null; testCertificate = null; if (certificate == null) { return(false); } var certificateText = Encoding.UTF8.GetString(certificate); if (string.IsNullOrEmpty(certificateText)) { return(false); } var colonIndex = certificateText.IndexOf(':'); if (colonIndex < 1) { return(false); } var identityToken = certificateText.Substring(0, colonIndex); identity = GetIdentity(identityToken); if (identity == null) { return(false); } foreach (var identityCertificate in identity.Certificates) { if (identityCertificate.Certificate.Length == certificate.Length) { var matching = true; for (var i = 0; i < certificate.Length; i++) { if (identityCertificate.Certificate[i] != certificate[i]) { matching = false; break; } } if (matching) { testCertificate = identityCertificate; } } } return(testCertificate != null); }
private IUnitTestElement GetOrCreateAndUpdateElement( ITestEntity testEntity, Func <ITestIdentity, ITestElement> factory) { var elementId = _unitTestElementIdFactory.Create( _testProvider.ID, testEntity.Project.GetPersistentID(), // TODO: TargetFrameworkId TargetFrameworkId.Default, testEntity.Identity.Absolute); var identity = new TestIdentity(elementId, testEntity.Identity); var element = _unitTestElementManager.GetElementById(identity.ElementId) as ITestElement ?? factory(identity); element.Update(testEntity.Text, explicitReason: null, categories: testEntity.Categories.Select(x => _unitTestElementCategoryFactory.Create(x))); return(element); }
public void Constructor_FromIdentity(Mock <IEntityIdentity> identity, string id) { // arrange identity .SetupGet(self => self.Tag) .Returns("test_identity"); identity .SetupGet(self => self.Value) .Returns(id.ToString); // act var taskId = new TestIdentity(identity.Object); // assert Assert.Equal(id, taskId.Id); Assert.Equal(id, taskId.Value); }
private void SetSession() { var tIdentity = new TestIdentity(); MakeSession(tIdentity); var identity = new ClaimsIdentity(tIdentity.AuthenticationType ?? "ApplicationCookie"); identity.AddClaim(new Claim(OwnerClaimTypes.TenantId, tIdentity.TenantId ?? "")); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, tIdentity.UserId ?? "")); identity.AddClaim(new Claim(OwnerClaimTypes.TimeDifference, tIdentity.TimeDiff.ToString())); //var identity = new ClaimsIdentity("ApplicationCookie"); //identity.AddClaim(new Claim(OwnerClaimTypes.TenantId, "B57F407F-53CB-4D8F-A7D8-EFBE0A213F68")); //identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "7BF86867-0C79-46AA-8BF9-6EEE6A98360A")); //identity.AddClaim(new Claim(OwnerClaimTypes.TimeDifference, "0")); var principal = new ClaimsPrincipal(identity); Thread.CurrentPrincipal = principal; }
public async void HandleExternalTask() { var identity = new TestIdentity(); var client = new HttpClient(); var url = "http://localhost:8000"; testObject = new ExternalTaskWorker <TestPayload, SampleResult>( url, identity, "TestTopic", 10, 10000, async(externalTask) => { return(await this.Callback(externalTask)); }); testObject.Start(); }
static void Main(string[] args) { Console.WriteLine("SQL Server Entity Framework Test..."); // 测试延迟加载. TestLazyLoading.DoTest(); // 测试 identity. TestIdentity.DoTest(); // 测试 存储过程 TestCallProcedure.DoTest(); // 测试 事务处理. TestTransaction.DoTest(); // 测试 多次查询. TestMulQuery.DoTest(); // 测试并发处理. TestConcurrency.DoTest(); // Model First 的测试. // TestModelFirst.DoTest(); Console.ReadLine(); }
private HttpContextBase GetHttpContext(string appPath) { var mockContext = MockRepository.GenerateMock <HttpContextBase>(); var mockRequest = MockRepository.GenerateMock <HttpRequestBase>(); if (!String.IsNullOrEmpty(appPath)) { mockRequest.Stub(o => o.ApplicationPath).Return(appPath); } Uri uri = new Uri("http://localhost/"); mockRequest.Stub(o => o.Url).Return(uri); mockRequest.Stub(o => o.PathInfo).Return(String.Empty); mockContext.Stub(o => o.Request).Return(mockRequest); mockContext.Stub(o => o.Session).Return(null); var mockResponse = MockRepository.GenerateMock <HttpResponseBase>(); mockResponse.Stub(o => o.ApplyAppPathModifier(null)).IgnoreArguments().Do((Func <string, string>)(s => s)); mockContext.Stub(o => o.Response).Return(mockResponse); mockRequest.Stub(o => o.Path).Return("Home/Index/"); var principal = MockRepository.GenerateMock <IPrincipal>(); mockContext.Stub(o => o.User).Return(principal); identity = new TestIdentity() { IsAuthenticated = false }; principal.Stub(o => o.Identity).Return(identity); return(mockContext); }
protected virtual void MakeSession(TestIdentity identity) { }
private HttpContextBase GetHttpContext(string appPath) { var mockContext = MockRepository.GenerateMock<HttpContextBase>(); var mockRequest = MockRepository.GenerateMock<HttpRequestBase>(); if (!String.IsNullOrEmpty(appPath)) { mockRequest.Stub(o => o.ApplicationPath).Return(appPath); } Uri uri = new Uri("http://localhost/"); mockRequest.Stub(o => o.Url).Return(uri); mockRequest.Stub(o => o.PathInfo).Return(String.Empty); mockContext.Stub(o => o.Request).Return(mockRequest); mockContext.Stub(o => o.Session).Return(null); var mockResponse = MockRepository.GenerateMock<HttpResponseBase>(); mockResponse.Stub(o => o.ApplyAppPathModifier(null)).IgnoreArguments().Do((Func<string, string>)(s => s)); mockContext.Stub(o => o.Response).Return(mockResponse); mockRequest.Stub(o => o.Path).Return("Home/Index/"); var principal = MockRepository.GenerateMock<IPrincipal>(); mockContext.Stub(o => o.User).Return(principal); identity = new TestIdentity() { IsAuthenticated = false }; principal.Stub(o => o.Identity).Return(identity); return mockContext; }
public void IdentityNullIfNotClaimsIdentityTest() { IIdentity identity = new TestIdentity(); Assert.Null(identity.GetUserId()); Assert.Null(identity.GetUserName()); }
protected override void MakeSession(TestIdentity identity) { identity.TenantId = "70DABE1F-33A4-4F28-9499-D38EDFC57644"; //identity.UserId = ""; }
public TestsFile ParseTestsFile(string testsFile) { TestsFile result = new TestsFile(); using (var fs = File.OpenRead(testsFile)) { using (var br = new BinaryReader(fs)) { TestsFileHeader header = new TestsFileHeader(); header.RecSizeLabel = ConvertToString(br.ReadBytes(8)); header.RecSize = br.ReadInt32(); header.Unknown = br.ReadInt32(); result.Header = header; result.Tests = new List<TestProperties>(); while (fs.Length > fs.Position) { var test = new TestProperties(); using (var ms = new MemoryStream(br.ReadBytes(header.RecSize))) { using (var br1 = new BinaryReader(ms)) { // 读取TestIdentity var identity = new TestIdentity(); // identity.Name = ConvertToString(br1.ReadBytes(21)); identity.Name = ConvertToGBString(br1.ReadBytes(21)); identity.Instrument = ConvertToString(br1.ReadBytes(11)); identity.GelSize = br1.ReadInt16(); identity.StainType = br1.ReadInt16(); test.Identity = identity; // test.bIFE = br1.ReadBoolean(); test.Units = ConvertToString(br1.ReadBytes(11)); test.TotalUnits = ConvertToString(br1.ReadBytes(11)); test.AutoEditOptions = br1.ReadByte(); test.Precision = br1.ReadInt16(); test.UnitsFullScale = br1.ReadInt16(); test.ImageContrast = br1.ReadInt16(); // 读取DemoIdentity var demos = new List<DemoIdentity>(); for (int i = 0; i < 10; i++) { DemoIdentity d = new DemoIdentity(); d.Label = ConvertToString(br1.ReadBytes(21)); d.Type = br1.ReadByte(); d.ASTMField = br1.ReadByte(); demos.Add(d); } test.Demo = demos; // 读取RangeSet var rs = new List<Range>(); for (int i = 0; i < 9; i++) { Range r = new Range(); r.Sex = ConvertToString(br1.ReadBytes(2)); r.Type = br1.ReadByte(); r.AgeLow = br1.ReadByte(); r.AgeLowUnits = br1.ReadByte(); r.AgeHigh = br1.ReadByte(); r.AgeHighUnits = br1.ReadByte(); rs.Add(r); } test.RangeSet = rs; br1.ReadByte(); // 读取Ratio var ratios = new List<Ratio>(); for (int i = 0; i < 2; i++) { Ratio r = new Ratio(); r.Label = Encoding.ASCII.GetString(br1.ReadBytes(12)); r.dRange = new List<KeyValuePair<double, double>>(); for (int j = 0; j < 9; j++) { KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble()); r.dRange.Add(t); } ratios.Add(r); } test.Ratio = ratios; // 读取Fraction var fractions = new List<Fraction>(); for (int i = 0; i < 10 + 1; i++) { Fraction f = new Fraction(); f.Label = ConvertToString(br1.ReadBytes(13)); f.Ratio = new List<byte>(); f.Ratio.Add(br1.ReadByte()); f.Ratio.Add(br1.ReadByte()); f.bIstd = br1.ReadBoolean(); f.dPctRange = new List<KeyValuePair<double, double>>(); for (int j = 0; j < 9; j++) { KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble()); f.dPctRange.Add(t); } f.dUnitsRange = new List<KeyValuePair<double, double>>(); for (int j = 0; j < 9; j++) { KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble()); f.dUnitsRange.Add(t); } fractions.Add(f); } test.Fraction = fractions; // 不读取了 //test.RstrctBandLabel = ConvertToString(br1.ReadBytes(18)); //test.Reserved = Encoding.ASCII.GetString(br1.ReadBytes(2)); //test.Options = br1.ReadByte(); } } result.Tests.Add(test); } } } return result; }
public TFile ParseTFile(string file) { TFile result = new TFile(); using (var fs = File.OpenRead(file)) { using (var br = new BinaryReader(fs)) { result.Header = new TFileHeader(); // 读取Identity var identity = new TestIdentity(); // identity.Name = ConvertToString(br.ReadBytes(21)); identity.Name = ConvertToGBString(br.ReadBytes(21)); identity.Instrument = ConvertToString(br.ReadBytes(11)); identity.GelSize = br.ReadInt16(); identity.StainType = br.ReadInt16(); result.Header.Identity = identity; // skip br.ReadBytes(220); // 读取count数组 byte nullValue = 0xFF; byte[] sampleSeqArray = br.ReadBytes(100); result.Header.Count = sampleSeqArray.TakeWhile(i => i != nullValue).ToArray(); int sampleCount = result.Header.Count.Length; // 读取数据 result.Datas = new List<TFileData>(); for (int i = 0; i < sampleCount; i++) { var data = new TFileData(); data.Patient = new PatientInfo(); for (int p = 0; p < 10; p++) { var demo = br.ReadBytes(21); var demoType = br.ReadByte(); if (demoType == 0) { data.Patient.Demographic.Add(ConvertToGBString(demo)); } if (demoType == 1) { data.Patient.Demographic.Add(ConvertToString(demo)); } } data.csStatus = ConvertToString(br.ReadBytes(21)); data.csDate = ConvertToString(br.ReadBytes(20)); data.Id = br.ReadByte(); data.Name = ConvertToGBString(br.ReadBytes(21)); data.Unknown = ConvertToString(br.ReadBytes(3)); result.Datas.Add(data); } } } return result; }