public void CanHandleDefaultValues() { //-- arrange var factoryCallCount = 0; Func <int> factory = () => { factoryCallCount++; return(0); }; var lazyUnderTest = new LazySlim <int>(factory); //-- act var actualFactoryCallCount0 = factoryCallCount; var actualValue1 = lazyUnderTest.Value; var actualFactoryCallCount1 = factoryCallCount; var actualValue2 = lazyUnderTest.Value; var actualFactoryCallCount2 = factoryCallCount; //-- assert actualValue1.Should().Be(0); actualValue2.Should().Be(0); actualFactoryCallCount0.Should().Be(0); actualFactoryCallCount1.Should().Be(1); actualFactoryCallCount2.Should().Be(1); }
public void CanInitializeWithFactory() { //-- arrange var value = new object(); var factoryCallCount = 0; Func <object> factory = () => { factoryCallCount++; return(value); }; var lazyUnderTest = new LazySlim <object>(factory); //-- act var actualFactoryCallCount0 = factoryCallCount; var actualValue1 = lazyUnderTest.Value; var actualFactoryCallCount1 = factoryCallCount; var actualValue2 = lazyUnderTest.Value; var actualFactoryCallCount2 = factoryCallCount; //-- assert actualValue1.Should().BeSameAs(value); actualValue2.Should().BeSameAs(value); actualFactoryCallCount0.Should().Be(0); actualFactoryCallCount1.Should().Be(1); actualFactoryCallCount2.Should().Be(1); }
/// <summary> /// Evaluates the specified lazy function, if necessary. /// </summary> /// <param name="lazy">The lazy.</param> public static void Evaluate <T>(this LazySlim <T> lazy) where T : class { if (lazy.IsValueCreated) { return; } var _ = lazy.Value; }
/// <summary> /// Initializes a new instance of the <see cref="T:PacketDotNet.Ieee80211.Ieee80211.LogicalLinkControl" /> class. /// </summary> /// <param name="byteArraySegment">byteArraySegment.</param> public LogicalLinkControl(ByteArraySegment byteArraySegment) { // set the header field, header field values are retrieved from this byte array Header = new ByteArraySegment(byteArraySegment) { Length = LogicalLinkControlFields.HeaderLength }; // parse the payload via an EthernetPacket method PayloadPacketOrData = new LazySlim <PacketOrByteArraySegment>(() => EthernetPacket.ParseNextSegment(Header, Type)); }
public void CanInitializeWithValue() { //-- arrange var value = new object(); var lazyUnderTest = new LazySlim <object>(value); //-- act var actualValue1 = lazyUnderTest.Value; var actualValue2 = lazyUnderTest.Value; //-- assert actualValue1.Should().BeSameAs(value); actualValue2.Should().BeSameAs(value); }
/// <summary> /// Initializes a new instance of the <see cref="PpiPacket" /> class. /// </summary> /// <param name="byteArraySegment"> /// A <see cref="ByteArraySegment" /> /// </param> public PpiPacket(ByteArraySegment byteArraySegment) { // slice off the header portion Header = new ByteArraySegment(byteArraySegment); Version = VersionBytes; Flags = FlagsBytes; // update the header size based on the headers packet length Header.Length = LengthBytes; LinkType = LinkTypeBytes; PpiFields = ReadPpiFields(); var commonField = FindFirstByType(PpiFieldType.PpiCommon) as PpiCommon; // parse the encapsulated bytes PayloadPacketOrData = new LazySlim <PacketOrByteArraySegment>(() => ParseNextSegment(Header, commonField)); }
public static HttpEndpointInjectorPort ServeRestApiRequests <TProtocol>(this HttpEndpointInjectorPort port) where TProtocol : MessageProtocol { var components = port.Components; var protocol = new LazySlim <TProtocol>(factory: () => components.Resolve <TProtocol>()); port.OnRequest = (context) => { var restApiService = components.Resolve <IRestApiService>(); return(restApiService.HandleHttpRequest(context, protocol.Value.ProtocolName)); }; port.OnConfiguration += new Action <IHttpEndpointConfig>((endpointConfig) => { var platformConfig = components.Resolve <IMessagingPlatformConfiguration>(); var staticFolders = components.ResolveAll <StaticResourceFolderDescription>(); foreach (var folder in staticFolders) { endpointConfig.StaticFolders.Add(ConfigureStaticResourceFolder(folder, platformConfig.NewHttpStaticFolderConfig())); } }); return(port); }
internal RadioPacket(ByteArraySegment byteArraySegment) { Log.Debug(""); // slice off the header portion Header = new ByteArraySegment(byteArraySegment) { Length = RadioFields.DefaultHeaderLength }; Version = VersionBytes; Length = LengthBytes; // update the header size based on the headers packet length Header.Length = Length; Present = ReadPresentFields(); RadioTapFields = ReadRadioTapFields(); //Before we attempt to parse the payload we need to work out if //the FCS was valid and if it will be present at the end of the frame var flagsField = this[RadioTapType.Flags] as FlagsRadioTapField; PayloadPacketOrData = new LazySlim <PacketOrByteArraySegment>(() => ParseNextSegment(Header.NextSegment(), flagsField)); }