Esempio n. 1
0
 public void OffsetOf_NonRuntimeField_ThrowsArgumentException()
 {
     AssertExtensions.Throws <ArgumentException>("fieldName", () => Marshal.OffsetOf(new NonRuntimeType(), "Field"));
 }
Esempio n. 2
0
 public void ObjectInitialization_InvalidSecurityDescriptor()
 {
     AssertExtensions.Throws <ArgumentNullException>("securityDescriptor",
                                                     () => new CustomDirectoryObjectSecurity(null));
 }
Esempio n. 3
0
 public void ToDictionary_ThrowArgumentNullExceptionWhenSourceIsNullElementSelector()
 {
     int[] source = null;
     AssertExtensions.Throws <ArgumentNullException>("source", () => source.ToDictionary(key => key, e => e));
 }
Esempio n. 4
0
        public void Test_GenerateManifest_InvalidEventSources()
        {
            TestUtilities.CheckNoEventSourcesRunning("Start");
            // specify AllowEventSourceOverride - this is needed for Sdt event sources and won't make a difference for Sdt ones
            var strictOptions = EventManifestOptions.Strict | EventManifestOptions.AllowEventSourceOverride;

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty));

            Exception e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions));

            Assert.Equal(GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e.Message);

            // starting with NuGet we allow non-void returning methods as long as they have the [Event] attribute
            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithReturnEventSource), string.Empty));

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithReturnEventSource), string.Empty, strictOptions));

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithReturnEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty));
            Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
            Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.OutOfRangeKwdEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_IllegalKeywordsValue", "Kwd1", "0x100000000000"),
                                     GetResourceString("EventSource_KeywordCollision", "Session3", "Kwd1", "0x100000000000")),
                         e.Message);

#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
            e = Assert.Throws <ArgumentException>(GetResourceString("EventSource_MaxChannelExceeded"),
                                                  () => EventSource.GenerateManifest(typeof(Sdt.TooManyChannelsEventSource), string.Empty));
#endif

#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
            e = Assert.Throws <ArgumentException>(GetResourceString("EventSource_EventWithAdminChannelMustHaveMessage", "WriteInteger", "Admin"),
                                                  () => EventSource.GenerateManifest(typeof(Sdt.EventWithAdminChannelNoMessageEventSource), string.Empty, strictOptions));
#endif // USE_ETW

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_IllegalOpcodeValue", "Op1", 3),
                                     GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1)),
                         e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_IllegalOpcodeValue", "Op1", 3),
                                     GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1)),
                         e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty));
            Assert.Equal(GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_EnumKindMismatch", "Op1", "EventKeywords", "Opcodes"),
                                     GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger")),
                         e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
            Assert.Equal(GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e.Message);

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty));

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e.Message);

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty));

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
                                     GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
                         e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
                                     GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
                         e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_EventNameReused", "WriteInteger"), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_EventNameReused", "WriteInteger"), e.Message);

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty));

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e.Message);

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty));

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e.Message);

            Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty));

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_UnsupportedMessageProperty", "WriteString", "Message = {0,12:G}"), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Keywords"),
                                     GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Tasks"),
                                     GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Opcodes")),
                         e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions));
            Assert.Equal(String.Join(Environment.NewLine,
                                     GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Keywords"),
                                     GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Tasks"),
                                     GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Opcodes")),
                         e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e.Message);

            e = AssertExtensions.Throws <ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions));
            Assert.Equal(GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e.Message);

            TestUtilities.CheckNoEventSourcesRunning("Stop");
        }
Esempio n. 5
0
 public void Ctor_NegativePageSize_ThrowsArgumentException()
 {
     AssertExtensions.Throws <ArgumentException>("value", () => new PageResultRequestControl(-1));
 }
 public void GetPathRoot_EmptyThrows_Desktop()
 {
     AssertExtensions.Throws <ArgumentException>("path", null, () => Path.GetPathRoot(string.Empty));
 }
 public void GetFullPath_Wildcards(char wildcard)
 {
     AssertExtensions.Throws <ArgumentException>("path", null, () => Path.GetFullPath("test" + wildcard + "ing"));
 }
 public void CurrencyDecimalSeparator_Set_Invalid()
 {
     AssertExtensions.Throws <ArgumentNullException>("CurrencyDecimalSeparator", () => new NumberFormatInfo().CurrencyDecimalSeparator = null);
     AssertExtensions.Throws <ArgumentException>(null, () => new NumberFormatInfo().CurrencyDecimalSeparator = "");
     Assert.Throws <InvalidOperationException>(() => NumberFormatInfo.InvariantInfo.CurrencyDecimalSeparator = "string");
 }
Esempio n. 9
0
 public void Ctor_NullName_ThrowsArgumentNullException()
 {
     AssertExtensions.Throws <ArgumentNullException>("name", () => new RegionInfo(null));
 }
Esempio n. 10
0
 public void ZeroBufferSizeThrows()
 {
     // Unfortunate pre-existing behavior of FileStream, we should look into enabling this sometime.
     AssertExtensions.Throws <ArgumentOutOfRangeException>("bufferSize", () => CreateFileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 0));
 }
Esempio n. 11
0
        public void GetEra_NullEraName_ThrowsArgumentNullException()
        {
            var format = new DateTimeFormatInfo();

            AssertExtensions.Throws <ArgumentNullException>("eraName", () => format.GetEra(null));
        }
Esempio n. 12
0
 public void NegativeBufferSizeThrows()
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("bufferSize", () => CreateFileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, -1));
 }
Esempio n. 13
0
 public void OffsetOf_NoLayoutPoint_ThrowsArgumentException()
 {
     AssertExtensions.Throws <ArgumentException>(null, () => Marshal.OffsetOf(typeof(NoLayoutPoint), nameof(NoLayoutPoint.x)));
     AssertExtensions.Throws <ArgumentException>(null, () => Marshal.OffsetOf <NoLayoutPoint>(nameof(NoLayoutPoint.x)));
 }
Esempio n. 14
0
 public void OffsetOf_NotMarshallable_ThrowsArgumentException(Type t, string fieldName)
 {
     AssertExtensions.Throws <ArgumentException>(null, () => Marshal.OffsetOf(t, fieldName));
 }
Esempio n. 15
0
 public void GetDirectoryName_ArgumentExceptions(string path)
 {
     // In NetFX we normalize and check invalid path chars
     AssertExtensions.Throws <ArgumentException>("path", null, () => Path.GetDirectoryName(path));
 }
Esempio n. 16
0
 public void Ctor_EmptyName_ThrowsArgumentException()
 {
     AssertExtensions.Throws <ArgumentException>("name", null, () => new RegionInfo(""));
 }
Esempio n. 17
0
 public void IsPathRooted_ArgumentExceptions(string path)
 {
     // In NetFX we check invalid path chars
     AssertExtensions.Throws <ArgumentException>("path", null, () => Path.IsPathRooted(path));
 }
Esempio n. 18
0
 public void Ctor_InvalidName_ThrowsArgumentException(string name)
 {
     AssertExtensions.Throws <ArgumentException>("name", () => new RegionInfo(name));
 }
Esempio n. 19
0
 public void GetFullPath_NotSupportedColons(string path)
 {
     // Throws via our invalid colon filtering (as part of FileIOPermissions)
     AssertExtensions.ThrowsAny <NotSupportedException, ArgumentException>(() => Path.GetFullPath(path));
 }
Esempio n. 20
0
 public void CopyTo_NullDestination_ThrowsArgumentNullException()
 {
     AssertExtensions.Throws <ArgumentNullException>("destination", () => Marshal.Copy(new short[10], 0, IntPtr.Zero, 0));
     AssertExtensions.Throws <ArgumentNullException>("destination", () => Marshal.Copy(new IntPtr(1), (short[])null, 0, 0));
 }
Esempio n. 21
0
 public void DateTimeFormat_Set_Invalid()
 {
     AssertExtensions.Throws <ArgumentNullException>("value", () => new CultureInfo("en-US").DateTimeFormat = null);                     // Value is null
     Assert.Throws <InvalidOperationException>(() => CultureInfo.InvariantCulture.DateTimeFormat            = new DateTimeFormatInfo()); // DateTimeFormatInfo.InvariantInfo is read only
 }
Esempio n. 22
0
 public void CopyTo_NullSource_ThrowsArgumentNullException()
 {
     AssertExtensions.Throws <ArgumentNullException>("source", () => Marshal.Copy((short[])null, 0, new IntPtr(1), 0));
     AssertExtensions.Throws <ArgumentNullException>("source", () => Marshal.Copy(IntPtr.Zero, new short[10], 0, 0));
 }
Esempio n. 23
0
 public static void NullArg_ThrowsException()
 {
     AssertExtensions.Throws <ArgumentNullException>("path", () => File.Encrypt(null));
     AssertExtensions.Throws <ArgumentNullException>("path", () => File.Decrypt(null));
 }
        public void QueryInterface_ZeroPointer_ThrowsArgumentNullException()
        {
            Guid iid = Guid.Empty;

            AssertExtensions.Throws <ArgumentNullException>("pUnk", () => Marshal.QueryInterface(IntPtr.Zero, ref iid, out IntPtr ppv));
        }
Esempio n. 25
0
        public void RemoveAuditRuleSpecific_InvalidObjectAuditRule()
        {
            var customObjectSecurity = new CustomDirectoryObjectSecurity();

            AssertExtensions.Throws <ArgumentNullException>("rule", () => customObjectSecurity.RemoveAuditRuleSpecific(null));
        }
Esempio n. 26
0
 public void Rfc5869DeriveKeyNullIkm()
 {
     AssertExtensions.Throws <ArgumentNullException>(
         "ikm",
         () => HKDF.DeriveKey(HashAlgorithmName.SHA1, null, 20, Array.Empty <byte>(), Array.Empty <byte>()));
 }
Esempio n. 27
0
        public void AddAccessRule_InvalidObjectAccessRule()
        {
            var customObjectSecurity = new CustomDirectoryObjectSecurity();

            AssertExtensions.Throws <ArgumentNullException>("rule", () => customObjectSecurity.AddAccessRule(null));
        }
Esempio n. 28
0
 public void GetFullPath_UNC_Invalid(string invalidPath)
 {
     AssertExtensions.Throws <ArgumentException>(null, () => Path.GetFullPath(invalidPath));
 }
 public static void ThrowsOnLeftNull()
 {
     AssertExtensions.Throws <ArgumentNullException>("left", () => Expression.Add(null, Expression.Constant("")));
 }
Esempio n. 30
0
 public void OffsetOf_NoSuchFieldName_ThrowsArgumentException()
 {
     AssertExtensions.Throws <ArgumentException>("fieldName", () => Marshal.OffsetOf(typeof(NonExistField), "NonExistField"));
     AssertExtensions.Throws <ArgumentException>("fieldName", () => Marshal.OffsetOf <NonExistField>("NonExistField"));
 }