public void UsesCreatorAfterReset() { bool didCallRef = false; var refLazy = new ResettableLazy <string>(() => { if (didCallRef) { return("Second"); } didCallRef = true; return("First"); }); _ = refLazy.Value; refLazy.Reset(); Assert.AreEqual("Second", refLazy.Value); bool didCallVal = false; var valLazy = new ResettableLazyValue <int>(() => { if (didCallVal) { return(1337); } didCallVal = true; return(42); }); _ = valLazy.Value; valLazy.Reset(); Assert.AreEqual(1337, valLazy.Value); }
internal GraphicsContext(GraphicsAdapter graphicsAdapter, IGraphicsSurface graphicsSurface) { _graphicsAdapter = graphicsAdapter; _graphicsSurface = graphicsSurface; _acquireNextImageSemaphore = new ResettableLazy <ulong>(CreateAcquireNextImageSemaphore); _commandBuffers = new ResettableLazy <IntPtr[]>(CreateCommandBuffers); _commandPool = new ResettableLazy <ulong>(CreateCommandPool); _device = new ResettableLazy <IntPtr>(CreateDevice); _deviceQueue = new ResettableLazy <IntPtr>(CreateDeviceQueue); _fences = new ResettableLazy <ulong[]>(CreateFences); _frameBuffers = new ResettableLazy <ulong[]>(CreateFrameBuffers); _graphicsQueueFamilyIndex = new ResettableLazy <uint>(FindGraphicsQueueFamilyIndex); _queueSubmitSemaphore = new ResettableLazy <ulong>(CreateQueueSubmitSemaphore); _renderPass = new ResettableLazy <ulong>(CreateRenderPass); _surface = new ResettableLazy <ulong>(CreateSurface); _swapChain = new ResettableLazy <ulong>(CreateSwapChain); _swapChainImageViews = new ResettableLazy <ulong[]>(CreateSwapChainImageViews); _ = _state.Transition(to: Initialized); // Do event hookups after we are in the initialized state, since an event could // technically fire while the constructor is still running. _graphicsSurface.SizeChanged += HandleGraphicsSurfaceSizeChanged; }
internal SCSlideLayout(SCSlideMaster slideMaster, SlideLayoutPart sldLayoutPart) { _slideMaster = slideMaster; SlideLayoutPart = sldLayoutPart; _shapes = new ResettableLazy <ShapeCollection>(() => ShapeCollection.CreateForSlideLayout(sldLayoutPart.SlideLayout.CommonSlideData.ShapeTree, this)); }
public GameViewModel() { gameCopy = new GameCopy(); gameStats = new ResettableLazy <IEnumerable <GameItemGroupViewModel> >(() => GameItemGrouping.GroupItems(GameCopy.Items)); }
internal SCParagraph(A.Paragraph aParagraph, SCTextBox textBox) { this.AParagraph = aParagraph; this.Level = GetInnerLevel(aParagraph); this.bullet = new Lazy <Bullet>(this.GetBullet); this.ParentTextBox = textBox; this.portions = new ResettableLazy <PortionCollection>(() => new PortionCollection(this.AParagraph, this)); }
public void ReturnTheFactoryResultWhenCalledOnce() { var rl = ResettableLazy.Create(() => TestResult); var result = rl.Value; result.Wait(); Assert.Equal(TestResult, result.Result); }
public void ReturnFalseWhenCalledBeforeValue() { var rl = new ResettableLazy <int>(() => TestResult); var result = rl.IsValueCreated; result.Wait(); Assert.Equal(false, result.Result); }
internal SCTableCell(SCTableRow parentTableRow, A.TableCell aTableCell, int rowIndex, int columnIndex) { this.ParentTableRow = parentTableRow; this.ATableCell = aTableCell; this.RowIndex = rowIndex; this.ColumnIndex = columnIndex; this.textBox = new ResettableLazy <SCTextBox>(this.GetTextBox); }
public WindowProvider() { _classAtom = new ResettableLazy <ushort>(CreateClassAtom); _nativeHandle = new ResettableLazy <GCHandle>(CreateNativeHandle); _windows = new ThreadLocal <Dictionary <IntPtr, Window> >(trackAllValues: true); _ = _state.Transition(to: Initialized); }
internal Category( ResettableLazy <List <X.Cell> > indexToXCell, int index, NumericValue cachedName) { _indexToXCell = indexToXCell; _index = index; _cachedName = cachedName; }
internal Category( ResettableLazy <List <X.Cell> > indexToXCell, int index, NumericValue cachedName, Category mainCategory) : this(indexToXCell, index, cachedName) { // TODO: what about creating a new separate class like MultiCategory:Category MainCategory = mainCategory; }
internal SCFont(A.Text aText, Portion portion) { this.aText = aText; this.size = new ResettableLazy <int>(this.GetSize); this.latinFont = new ResettableLazy <A.LatinFont>(this.GetALatinFont); this.colorFormat = new Lazy <ColorFormat>(() => new ColorFormat(this)); this.Portion = portion; this.aFontScheme = ((Shape)portion.ParentParagraph.ParentTextBox.ParentTextBoxContainer).ThemePart.Theme.ThemeElements.FontScheme; }
public HashStorage(ISimpleDataProvider dataProvider, IDbConnectionProvider dbConnection, ILogger logger) { _dataProvider = dataProvider; _dbConnection = dbConnection; _logger = logger; _hashStorage = new ResettableLazy <HashSet <byte[]> >(InitHashSet); _tableName = OrmUtils.GetTableName <TData>(); }
/// <summary>Initializes a new instance of the <see cref="Application" /> class.</summary> /// <param name="compositionAssemblies">The <see cref="Assembly" /> instances to search for type exports.</param> /// <exception cref="ArgumentNullException"><paramref name="compositionAssemblies" /> is <c>null</c>.</exception> public Application(params Assembly[] compositionAssemblies) { ThrowIfNull(compositionAssemblies, nameof(compositionAssemblies)); _compositionAssemblies = compositionAssemblies; _parentThread = Thread.CurrentThread; _compositionHost = new ResettableLazy <CompositionHost>(CreateCompositionHost); _ = _state.Transition(to: Stopped); }
public void ReturnTrueWhenCalledAfterValue() { var rl = new ResettableLazy <int>(() => TestResult); rl.Value.Wait(); var result = rl.IsValueCreated; result.Wait(); Assert.Equal(true, result.Result); }
public void IsEmptyByDefault() { var refLazy = new ResettableLazy <string>(() => ""); Assert.IsFalse(refLazy.HasValue); var valLazy = new ResettableLazyValue <int>(() => 0); Assert.IsFalse(valLazy.HasValue); }
public void TakesValueFromCreator() { var refLazy = new ResettableLazy <string>(() => "Hello World"); Assert.AreEqual("Hello World", refLazy.Value); var valLazy = new ResettableLazyValue <int>(() => 42); Assert.AreEqual(42, valLazy.Value); }
public void ReturnTheFactoryResultWhenCalledAfterReset() { var rl = ResettableLazy.Create(() => Task.FromResult(TestResult)); rl.Value.Wait(); rl.Reset(); var result = rl.Value; result.Wait(); Assert.Equal(TestResult, result.Result); }
internal SlideTable( OpenXmlCompositeElement pShapeTreeChild, ILocation innerTransform, ShapeContext spContext, SCSlide slide) : base(slide, pShapeTreeChild) { this.innerTransform = innerTransform; Context = spContext; rowCollection = new ResettableLazy <RowCollection>(() => RowCollection.Create(this, (P.GraphicFrame)PShapeTreeChild)); pGraphicFrame = pShapeTreeChild as P.GraphicFrame; }
public ExtendedEventDataSaver(IDbConnectionProvider connectionProvider, IQueryTextStoringService queryTextStoringService, IDateRepository dateRepository, ILogger <ExtendedEventDataSaver> logger) { _connectionProvider = connectionProvider; _queryTextStoringService = queryTextStoringService; _dateRepository = dateRepository; _logger = logger; _lockModeRepository = new SimpleLookupRepository <LockingMode>(connectionProvider); _lastQueryDate = new ResettableLazy <DateTime>(connectionProvider.GetLastQueryDate <LongInfoRecord>); _lastDeadLockDate = new ResettableLazy <DateTime>(connectionProvider.GetLastQueryDate <DeadLockInfoRecord>); }
public void CanBeInitialized() { var refLazy = new ResettableLazy <string>(() => "", "Hello World"); Assert.IsTrue(refLazy.HasValue); Assert.AreEqual("Hello World", refLazy.Value); var valLazy = new ResettableLazyValue <int>(() => 0, 42); Assert.IsTrue(valLazy.HasValue); Assert.AreEqual(valLazy.Value, 42); }
public void IsNotEmptyAfterAccess() { var refLazy = new ResettableLazy <string>(() => ""); _ = refLazy.Value; Assert.IsTrue(refLazy.HasValue); var valLazy = new ResettableLazyValue <int>(() => 0); _ = valLazy.Value; Assert.IsTrue(valLazy.HasValue); }
public void CauseOnlySingleCallOfTheFactoryWhenCalledTwice() { var count = 0; var rl = new ResettableLazy <int>(() => { count++; return(TestResult); }); rl.Value.Wait(); rl.Value.Wait(); Assert.Equal(1, count); }
public MappedDB() { foreach (var moduleType in Enum.GetValues(typeof(ModuleType)).Cast <ModuleType>()) { modules.Add(moduleType, new Dictionary <UID, Row>()); } fairiesByIndex = new ResettableLazy <IReadOnlyDictionary <int, FairyRow> >( () => Fairies.ToDictionary(f => f.CardId.EntityId, f => f)); itemsByIndex = new ResettableLazy <IReadOnlyDictionary <int, ItemRow> >( () => Items.ToDictionary(i => i.CardId.EntityId, i => i)); spellsByIndex = new ResettableLazy <IReadOnlyDictionary <int, SpellRow> >( () => Spells.ToDictionary(s => s.CardId.EntityId, s => s)); }
private DispatchProvider() { _dispatchers = new ConcurrentDictionary <Thread, IDispatcher>(); _dispatcherExitRequestedAtom = new ResettableLazy <UIntPtr>(CreateDispatcherExitRequestedAtom); _display = new ResettableLazy <UIntPtr>(CreateDisplay); _systemIntPtrAtom = new ResettableLazy <UIntPtr>(CreateSystemIntPtrAtom); _windowProviderCreateWindowAtom = new ResettableLazy <UIntPtr>(CreateWindowProviderCreateWindowAtom); _windowWindowProviderAtom = new ResettableLazy <UIntPtr>(CreateWindowWindowProviderAtom); _wmProtocolsAtom = new ResettableLazy <UIntPtr>(CreateWmProtocolsAtom); _wmDeleteWindowAtom = new ResettableLazy <UIntPtr>(CreateWmDeleteWindowAtom); _ = _state.Transition(to: Initialized); }
public void CanBeReset() { var refLazy = new ResettableLazy <string>(() => ""); _ = refLazy.Value; refLazy.Reset(); Assert.IsFalse(refLazy.HasValue); var valLazy = new ResettableLazyValue <int>(() => 0); _ = valLazy.Value; valLazy.Reset(); Assert.IsFalse(valLazy.HasValue); }
public void CauseOnlySingleCallOfTheFactoryWhenCalledByMultipleThreads() { var count = 0; var rl = new ResettableLazy <int>(() => { return(Task.Run(() => { count++; return TestResult; })); }); Enumerable.Repeat(string.Empty, 20).AsParallel().ToList().ForEach(_ => rl.Value.Wait()); Assert.Equal(1, count); }
public void Value() { var func = Substitute.For <Func <bool> >(); func.Invoke().Returns(true); var rl = new ResettableLazy <bool>(func); rl.Value.Should().BeTrue(); func.Received(1).Invoke(); rl.Value.Should().BeTrue(); func.Received(1).Invoke(); rl.Reset(); rl.Value.Should().BeTrue(); func.Received(2).Invoke(); }
public void DoesNotCallCreatorEarly() { bool didCallRef = false; var refLazy = new ResettableLazy <string>(() => { didCallRef = true; return(""); }); Assert.IsFalse(didCallRef); _ = refLazy.Value; Assert.IsTrue(didCallRef); bool didCallVal = false; var valLazy = new ResettableLazyValue <int>(() => { didCallVal = true; return(0); }); Assert.IsFalse(didCallVal); _ = valLazy.Value; Assert.IsTrue(didCallVal); }
protected void Initialize( Func <Application> application, Func <List <Action> > actions, Func <List <ClaimSet> > claimSets, Func <List <ResourceClaim> > resourceClaims, Func <List <AuthorizationStrategy> > authorizationStrategies, Func <List <ClaimSetResourceClaimAction> > claimSetResourceClaimActions, Func <List <ResourceClaimAction> > resourceClaimActions) { Application = new ResettableLazy <Application>(application); Actions = new ResettableLazy <List <Action> >(actions); ClaimSets = new ResettableLazy <List <ClaimSet> >(claimSets); ResourceClaims = new ResettableLazy <List <ResourceClaim> >(resourceClaims); AuthorizationStrategies = new ResettableLazy <List <AuthorizationStrategy> >(authorizationStrategies); ClaimSetResourceClaimActions = new ResettableLazy <List <ClaimSetResourceClaimAction> >(claimSetResourceClaimActions); ResourceClaimActions = new ResettableLazy <List <ResourceClaimAction> >(resourceClaimActions); }
public void SetUp() { _resettableLazy = new ResettableLazy<Lazy<int>, int>(() => new Lazy<int>(() => 0)); }