protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["jobtoken"])) { string decrypted = Decrypt(Request.QueryString["jobtoken"], "Dshd*&^*@dsdss", "237w&@2d", "SHA1", 2, "&s2hfyDjuf372*73", 256); string[] splitted = decrypted.Split('&'); if (splitted.Length > 1) { int jobId; int.TryParse(splitted[0], out jobId); int substId; int.TryParse(splitted[1], out substId); int type; int.TryParse(splitted[2], out type); Job job = new Job(jobId); Substitute substitute = new Substitute(substId); Miami.Substitute.Dal.User user = new Miami.Substitute.Dal.User(); DataView userView = user.LoadForMain(substitute.UserId); string confirmNote = String.Format("Confirmed by Substitute {0} on {1} {2} by clicking email link", userView[0]["FirstName"].ToString().Trim() + " " + userView[0]["LastName"].ToString().Trim(), DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()); if (job.m_statusId == 3) { (new Miami.Substitute.Bll.Job()).ConfirmJob(jobId, substId, type, confirmNote); if (type == 2) Message.Text = "You have successfully confirmed your job assignment."; else Message.Text = "You have declined your job assignment."; } else { if (job.m_statusId == 2) Message.Text = "Job was already confirmed."; else Message.Text = "Job was already declined."; } } } }
public static void CannotCallGetTargetTypeNameWithNullClassModel() { Assert.Throws <ArgumentNullException>(() => Substitute.For <IFrameworkSet>().GetTargetTypeName(default(ClassModel), false)); }
public ProcessorTests() { _reader = Substitute.For <IReader>(); _mapper = Substitute.For <IMapper>(); _writer = Substitute.For <IWriter>(); }
public DefaultContentReferencePropertyHandlerTests() { this._urlHelper = Substitute.For <IUrlHelper>(); this._sut = new DefaultContentReferencePropertyHandler(this._urlHelper); }
public void SetUp() { _fakeTimer = Substitute.For <ITimer>(); _uut = new UserCache(_fakeTimer); _fakeUsers = FakeUserGenerator.GenerateFakeUsers(50000); }
private static IFolder TemporaryFolder() { var ff = new FolderFactory(Substitute.For <INuKeeperLogger>()); return(ff.UniqueTemporaryFolder()); }
public void Free_the_instance_of_a_show_when_the_last_consumer_released_it() { var watcherPool = new ShowReservationsWatcherPool(Substitute.For <IProvideReservedSeats>()); }
public void Constructor_StoredProcedureNameNull_Throws() { Assert.Throws <ArgumentNullException>(() => new SqlDbStoredProcedureHealthCheckStrategy(Substitute.For <IDbConnectionProvider>(), null)); }
public void Setup() { _wikiaHttpClient = Substitute.For <IWikiaHttpClient>(); _sut = new WikiArticleList(Url, WikiaSettings.ApiVersion, _wikiaHttpClient); }
public void Arrange() { var director = Substitute.For <IGetUnitsDirector>(); controller = new UnitsController(director); }
public void ConfirmJob(int jobId, int substituteId, int status, string confirmNote) { DalJob.ConfirmJob(jobId, substituteId, status, confirmNote); NoticeSystem.NoticeType type; if (status == 2) type = NoticeSystem.NoticeType.JobConfirmedBySubstitute; else type = NoticeSystem.NoticeType.JobDeclinedBySubstitute; Substitute substitute = new Substitute(substituteId); NoticeSystem noticeSystem = new NoticeSystem(jobId, type, substitute.UserId, 0); noticeSystem.Send(); }
public DataView LoadAvailables(int jobId) { if (DalSubstitute.LoadAvailables(jobId)) { int substituteId = 0; int locationId = 0; bool isAvailable; Job job = new Job(jobId); Substitute substitute = new Substitute(); Dal.Preferred pref = new Miami.Substitute.Dal.Preferred(); Dal.SubstituteExceptions substituteExceptions = new Miami.Substitute.Dal.SubstituteExceptions(); DataRowView drv; DalSubstitute.DefaultView.Table.Columns.Add("IsApplied"); DalSubstitute.DefaultView.Table.Columns.Add("TimeWorks"); DalSubstitute.DefaultView.Table.Columns.Add("DatetimeStart"); DalSubstitute.DefaultView.Table.Columns.Add("VisibleAssign"); foreach (DataRow dr in DalSubstitute.DefaultView.Table.Rows) { if (dr["SubstituteId"] != null && dr["SubstituteId"] != DBNull.Value) { substituteId = Convert.ToInt32(dr["SubstituteId"]); substitute = new Substitute(substituteId); locationId = Convert.ToInt32(dr["JobLocationId"]); isAvailable = !substituteExceptions.IsOverlapped(substitute.UserId, job.DatetimeStart, job.DatetimeEnd); drv = job.LoadLastJobBySubstitute(substituteId); if (drv != null) { dr["TimeWorks"] = drv["TimeWorks"]; dr["DatetimeStart"] = drv["DatetimeStart"]; } if (job.IsOverlap(jobId, substituteId)) { dr["IsApplied"] = "<img src='Images/clerkassigned.gif' border='0'>"; dr["VisibleAssign"] = 0; } else if (!isAvailable) { dr["IsApplied"] = "<img src='Images/notapplied.gif' border='0'>"; dr["VisibleAssign"] = 0; } else { if (job.LoadSubstituteJob(jobId, substituteId)) dr["IsApplied"] = "<img src='Images/applied.gif' border='0'>"; else dr["IsApplied"] = "<img src='Images/blue.gif' border='0'>"; dr["VisibleAssign"] = 1; } } else { dr["IsApplied"] = "<img src='Images/notapplied.gif' border='0'>"; dr["VisibleAssign"] = 0; } } DalSubstitute.DefaultView.Sort = "IsClerkPreferred DESC, IsPreferred DESC"; return DalSubstitute.DefaultView; } else return null; }
Expression GetBaseInitCall (ConstructorDeclaration c, Substitute subs) { var thisInit = c.Initializer; var i = new InvocationExpression ( new BaseReferenceExpression (), thisInit.Arguments.Select (x => x.Clone ())); i.AcceptVisitor (subs); return i; }
public override void VisitTypeDeclaration (TypeDeclaration typeDeclaration) { base.VisitTypeDeclaration (typeDeclaration); var ctors = typeDeclaration.Members.OfType<ConstructorDeclaration> ().Where (x => (x.Modifiers & Modifiers.Static)==0).ToList (); if (ctors.Count == 0) return; if (ctors.Count > 1) { for (int i = 0; i < ctors.Count; i++) { var c = ctors [i]; c.Name = "constructor_" + i; } } // // Make sure everyone has a super call // foreach (var c in ctors) { if (c.Initializer.IsNull) { c.Initializer = new ConstructorInitializer { ConstructorInitializerType = ConstructorInitializerType.Base }; } } // // Move this to a call // foreach (var c in ctors) { if (c.Initializer.ConstructorInitializerType == ConstructorInitializerType.This) { var thisInit = c.Initializer; var md = GetMethodDef (thisInit); var thisCtor = ctors.FirstOrDefault (x => GetMethodDef (x) == (md)); // // Inline this // var sup = new InvocationExpression (new MemberReferenceExpression (new ThisReferenceExpression (), thisCtor.Name), thisInit.Arguments.Select (x => x.Clone ())); c.Body.InsertChildBefore (c.Body.FirstChild, new ExpressionStatement (sup), BlockStatement.StatementRole); // // Find the new super() // var subs = new Substitute (); ConstructorInitializer baseInit = null; if (baseInit == null) { subs.Subs = thisCtor.Parameters.Zip (thisInit.Arguments, (x, y) => Tuple.Create (x, y)).ToDictionary (x => x.Item1.Name, x => x.Item2); var i = thisCtor.Initializer; if (i.ConstructorInitializerType == ConstructorInitializerType.Base) { baseInit = (ConstructorInitializer)i.Clone (); } } if (baseInit == null) { throw new NotSupportedException ("This initializer to this initializer not supported"); } foreach (var a in baseInit.Arguments) { a.AcceptVisitor (subs); } c.Initializer = baseInit; } } // // // if (ctors.Count == 1) { var c = ctors [0]; var sup = GetBaseInitCall (c, new Substitute ()); c.Body.InsertChildBefore (c.Body.FirstChild, new ExpressionStatement (sup), BlockStatement.StatementRole); ctors [0].Initializer.Remove (); } else { // // Synthesize the 1 constructor // var newCtor = new ConstructorDeclaration { Body = new BlockStatement (), Name = "constructor", }; var diffs = GetDiffs (ctors.Select (x => x.Parameters.ToList ()).ToList ()); newCtor.Parameters.AddRange (diffs.Item1); for (int i = 0; i < diffs.Item2.Count; i++) { var diff = diffs.Item2 [i]; var c = ctors [i]; var ss = ((BlockStatement)diff.TrueStatement); var subs = new Substitute (); var args = c.Parameters.ToList (); for (int j = 0; j < args.Count; j++) { var p = diffs.Item1 [j]; subs.Subs [args [j].Name] = new IdentifierExpression (p.Name); } ss.Add (GetBaseInitCall (c, subs)); ss.Add (new InvocationExpression ( new MemberReferenceExpression (new ThisReferenceExpression (), c.Name), diffs.Item1.Take (c.Parameters.Count).Select (x => new IdentifierExpression (x.Name)))); if (i + 1 < diffs.Item2.Count) { ss.Add (new ReturnStatement ()); newCtor.Body.Add (diff); } else { foreach (var x in ss.Statements) { x.Remove (); newCtor.Body.Add (x); } } } typeDeclaration.InsertChildBefore (ctors [0], newCtor, Roles.TypeMemberRole); foreach (var c in ctors) { var body = c.Body; body.Remove (); // // Create the implementation method // var m = new MethodDeclaration { Name = c.Name, Body = body, ReturnType = new PrimitiveType ("void"), Modifiers = Modifiers.Private, }; m.Parameters.AddRange (c.Parameters.Select (x => (ParameterDeclaration)x.Clone ())); foreach (var p in m.Parameters) { if (!p.DefaultExpression.IsNull) p.DefaultExpression.Remove (); } c.ReplaceWith (m); // // Insert overload prototype // var mo = new ConstructorDeclaration { }; mo.Parameters.AddRange (c.Parameters.Select (x => (ParameterDeclaration)x.Clone ())); foreach (var p in mo.Parameters) { if (!p.DefaultExpression.IsNull) p.DefaultExpression.Remove (); } typeDeclaration.InsertChildBefore (newCtor, mo, Roles.TypeMemberRole); } } }
public static void CannotCallGetTargetFileNameWithInvalidSourceFileName(string value) { Assert.Throws <ArgumentNullException>(() => Substitute.For <IGenerationOptions>().GetTargetFileName(value)); }
private string ProcessNamesInString(string expression, Substitute[] processors) { StringBuilder result = new StringBuilder(); int pos = 0; do { Match m = s_variableName.Match(expression, pos); if (!m.Success) { break; // failed to match a name } result.Append(expression.Substring(pos, m.Index - pos)); pos = m.Index; bool found = false; foreach (var p in processors) { string repl = p(m); if (repl != null) { result.Append(repl); found = true; break; // found a substitute } } if (!found) { result.Append(m.Value); // no name replacement to perform } pos = m.Index + m.Length; Match sub = s_subfieldNameHere.Match(expression, pos); // span the subfields if (sub.Success) { result.Append(expression.Substring(pos, sub.Length)); pos = pos + sub.Length; } } while (pos < expression.Length); if (pos < expression.Length) { result.Append(expression.Substring(pos, expression.Length - pos)); } return result.ToString(); }
public void NS2007_CanNotProvideConstructorArgumentsWhenSubstitutingForADelegate() { Substitute.For <Action>(1); Substitute.For(new[] { typeof(Action) }, new object[] { 1 }); SubstitutionContext.Current.SubstituteFactory.Create(new[] { typeof(Action) }, new object[] { 1 }); }
public void MapToProperty_MediaUrlWithFlag_ReturnsModifiedUrl( SitecoreInfoMediaUrlOptions option ) { //Assign var mapper = new SitecoreInfoMapper(); var config = new SitecoreInfoConfiguration(); config.Type = SitecoreInfoType.MediaUrl; config.MediaUrlOptions = option; mapper.Setup(new DataMapperResolverArgs(null, config)); var itemId = new ID("031501A9C7F24596BD659276DA3A627A"); string expected = "media url"; Sitecore.Context.Site = null; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem", itemId) { Fields = { new FakeDbField(new ID("{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}"), "DataMappersEmptyItem DisplayName") }, } }) { Func<MediaUrlOptions, bool> pred = x => { switch (option) { case SitecoreInfoMediaUrlOptions.Default: return true; case SitecoreInfoMediaUrlOptions.RemoveExtension: return x.IncludeExtension == false; case SitecoreInfoMediaUrlOptions.LowercaseUrls: return x.LowercaseUrls == true; default: return false; } }; Sitecore.Resources.Media.MediaProvider mediaProvider = Substitute.For<Sitecore.Resources.Media.MediaProvider>(); mediaProvider .GetMediaUrl( Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == itemId), Arg.Is<MediaUrlOptions>(x => pred(x)) ) .Returns(expected); using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider)) { var item = database.GetItem("/sitecore/content/TestItem"); Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists"); var dataContext = new SitecoreDataMappingContext(null, item, null); //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); } } }
public override void VisitMethodDeclaration (MethodDeclaration methodDeclaration) { base.VisitMethodDeclaration (methodDeclaration); var hasRefs = methodDeclaration.Parameters.Any (IsRefParam); if (!hasRefs) return; var sub = new Substitute (); foreach (var p in methodDeclaration.Parameters.Where (IsRefParam).ToList ()) { var pty = ((ComposedType)p.Type).BaseType; var access = new IndexerExpression (new IdentifierExpression (p.Name), new PrimitiveExpression (0)); var ptd = GetTypeDef (pty); if (ptd != null) access.AddAnnotation (ptd); sub.Subs [p.Name] = access; p.ParameterModifier = ParameterModifier.None; var c = new ComposedType { BaseType = p.Type.Clone (), }; c.ArraySpecifiers.Add (new ArraySpecifier (1)); p.Type = c; } methodDeclaration.Body.AcceptVisitor (sub); }
public void Setup() { LoggingHelper.InitConsoleLogger("Test", LoggingLevel.Off); var startupConditions = Substitute.For <ICheckAllStartupConditions>(); var starter = Substitute.For <IMaybePipedApplicationStarter>(); starter.StartupConditions.Returns(startupConditions); _resolver = Substitute.For <IAppStartResolver>(); // We need some special syntax here to make NSubsitute work here: .Returns(x => new MainWindowStart(...)); _resolver.ResolveAppStart <MainWindowStart>().Returns(x => new MainWindowStart(null, starter, Substitute.For <IPdfArchitectCheck>(), Substitute.For <IMainWindowThreadLauncher>())); _resolver.ResolveAppStart <DragAndDropStart>().Returns(x => new DragAndDropStart(Substitute.For <IFileConversionHandler>(), starter)); _resolver.ResolveAppStart <PrintFileStart>().Returns(x => new PrintFileStart(Substitute.For <ICheckAllStartupConditions>(), Substitute.For <IPrintFileHelper>(), null)); _resolver.ResolveAppStart <NewPsJobStart>().Returns(x => new NewPsJobStart(null, null, starter, null, null)); _resolver.ResolveAppStart <NewPdfJobStart>().Returns(x => new NewPdfJobStart(null, null, starter, null, null)); _resolver.ResolveAppStart <NewPrintJobStart>().Returns(x => new NewPrintJobStart(null, null, null, starter, null)); _resolver.ResolveAppStart <InitializeDefaultSettingsStart>().Returns(x => new InitializeDefaultSettingsStart(null, null, null, Substitute.For <IInstallationPathProvider>(), Substitute.For <IDataStorageFactory>())); // TODO: Add tests of thr Run() method as it is testable now }
public void TestInitialize() { _logger = Substitute.For <ILogger>(); }
public void SetUp() { AttachmentExtractorSettings.AttachmentExtractorType = AttachmentExtractorType.Custom; _extractor = Substitute.For <IAttachmentExtractor>(); AttachmentExtractorSettings.CustomAttachmentExtractor = _extractor; }
public CategoryControllerTests() { repo = Substitute.For <ICategoryRepository>(); underTest = new CategoryController(repo); }
public void SetUp() { _managedProcessFactory = Substitute.For <ManagedProcess.Factory>(); }
public void Sets_clique_block_producer_properly() { CliqueConfig cliqueConfig = new CliqueConfig(); IBlockTree blockTree = Substitute.For <IBlockTree>(); Signer signer = new Signer(ChainId.Ropsten, TestItem.PrivateKeyA, LimboLogs.Instance); CliqueBlockProducer producer = new CliqueBlockProducer( Substitute.For <ITxSource>(), Substitute.For <IBlockchainProcessor>(), Substitute.For <IStateProvider>(), blockTree, Substitute.For <ITimestamper>(), Substitute.For <ICryptoRandom>(), Substitute.For <ISnapshotManager>(), new CliqueSealer(signer, cliqueConfig, Substitute.For <ISnapshotManager>(), LimboLogs.Instance), new TargetAdjustedGasLimitCalculator(GoerliSpecProvider.Instance, new MiningConfig()), cliqueConfig, LimboLogs.Instance); SnapshotManager snapshotManager = new SnapshotManager(CliqueConfig.Default, new MemDb(), Substitute.For <IBlockTree>(), NullEthereumEcdsa.Instance, LimboLogs.Instance); CliqueBridge bridge = new CliqueBridge(producer, snapshotManager, blockTree); Assert.DoesNotThrow(() => bridge.CastVote(TestItem.AddressB, true)); Assert.DoesNotThrow(() => bridge.UncastVote(TestItem.AddressB)); Assert.DoesNotThrow(() => bridge.CastVote(TestItem.AddressB, false)); Assert.DoesNotThrow(() => bridge.UncastVote(TestItem.AddressB)); }
private protected override Task <SnsMessagePublisher> CreateSystemUnderTestAsync() { var topic = new SnsMessagePublisher(TopicArn, Sns, _serializationRegister, NullLoggerFactory.Instance, Substitute.For <IMessageSubjectProvider>()) { MessageResponseLogger = (r, m) => { _response = r; _message = m; } }; return(Task.FromResult(topic)); }
/// <summary> /// 测试初始化 /// </summary> public UnitOfWorkManagerTest() { _unitOfWork = Substitute.For <IUnitOfWork>(); _unitOfWork2 = Substitute.For <IUnitOfWork>(); _manager = new UnitOfWorkManager(); }
public void SetUp() { _factory = Substitute.For <IRequestFactory>(); _descendant = new WindowsLiveClientDescendant( _factory, Substitute.For <IClientConfiguration>()); }
protected override SnsTopicByName CreateSystemUnderTest() { var topic = new SnsTopicByName("TopicName", _sns, _serialisationRegister, Substitute.For <ILoggerFactory>(), Substitute.For <SnsWriteConfiguration>(), Substitute.For <IMessageSubjectProvider>()) { MessageResponseLogger = (r, m) => { _response = r; _message = m; } }; topic.ExistsAsync().GetAwaiter().GetResult();; return(topic); }
public BlockValidatorBuilder() { TestObject = Substitute.For <IBlockValidator>(); }
public static void CannotCallGetTargetFileNameWithNullSourceFileName() { Assert.Throws <ArgumentNullException>(() => Substitute.For <IGenerationOptions>().GetTargetFileName(default(string))); }
public async Task ReturnsEveryPageOfIssues() { var firstPageUrl = new Uri("repos/fake/repo/issues", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); var firstPageLinks = new Dictionary <string, Uri> { { "next", secondPageUrl } }; var firstPageResponse = new ApiResponse <List <Issue> > ( CreateResponseWithApiInfo(firstPageLinks), new List <Issue> { CreateIssue(1), CreateIssue(2), CreateIssue(3) } ); var thirdPageUrl = new Uri("https://example.com/page/3"); var secondPageLinks = new Dictionary <string, Uri> { { "next", thirdPageUrl } }; var secondPageResponse = new ApiResponse <List <Issue> > ( CreateResponseWithApiInfo(secondPageLinks), new List <Issue> { CreateIssue(4), CreateIssue(5), CreateIssue(6) } ); var lastPageResponse = new ApiResponse <List <Issue> > ( new Response(), new List <Issue> { CreateIssue(7) } ); var gitHubClient = Substitute.For <IGitHubClient>(); gitHubClient.Connection.Get <List <Issue> >(Arg.Is(firstPageUrl), Arg.Is <Dictionary <string, string> >(d => d.Count == 4 && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), Arg.Any <string>()) .Returns(Task.Factory.StartNew <IApiResponse <List <Issue> > >(() => firstPageResponse)); gitHubClient.Connection.Get <List <Issue> >(secondPageUrl, null, null) .Returns(Task.Factory.StartNew <IApiResponse <List <Issue> > >(() => secondPageResponse)); gitHubClient.Connection.Get <List <Issue> >(thirdPageUrl, null, null) .Returns(Task.Factory.StartNew <IApiResponse <List <Issue> > >(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); var results = await client.GetAllForRepository("fake", "repo").ToArray(); Assert.Equal(7, results.Length); Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number); Assert.Equal(secondPageResponse.Body[1].Number, results[4].Number); Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number); }
public void NS2006_CanNotProvideConstructorArgumentsWhenSubstitutingForAnInterface() { Substitute.For <IFoo>(1); Substitute.For(new[] { typeof(IFoo) }, new object[] { 1 }); SubstitutionContext.Current.SubstituteFactory.Create(new[] { typeof(IFoo) }, new object[] { 1 }); }
public void SetUp() { _repository = Substitute.For<ICommands>(); _queries = Substitute.For<IQueries>(); _logger = Substitute.For<ILogger<ProductInteractor>>(); }
public void Setup() { output = Substitute.For <IOutput>(); uut = new Display(output); }
public void SetUp() { _output = Substitute.For <IOutput>(); _light = new Light(_output); }
public ShogiGameShould() { _boardRenderMock = Substitute.For <IBoardRender>(); _boardMock = Substitute.For <IBoard>(); }
public SubstituteExample(Substitute substitute) { this.substitute = substitute; }