public void OffsetOf_NonRuntimeField_ThrowsArgumentException() { AssertExtensions.Throws <ArgumentException>("fieldName", () => Marshal.OffsetOf(new NonRuntimeType(), "Field")); }
public void ObjectInitialization_InvalidSecurityDescriptor() { AssertExtensions.Throws <ArgumentNullException>("securityDescriptor", () => new CustomDirectoryObjectSecurity(null)); }
public void ToDictionary_ThrowArgumentNullExceptionWhenSourceIsNullElementSelector() { int[] source = null; AssertExtensions.Throws <ArgumentNullException>("source", () => source.ToDictionary(key => key, e => e)); }
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"); }
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"); }
public void Ctor_NullName_ThrowsArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("name", () => new RegionInfo(null)); }
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)); }
public void GetEra_NullEraName_ThrowsArgumentNullException() { var format = new DateTimeFormatInfo(); AssertExtensions.Throws <ArgumentNullException>("eraName", () => format.GetEra(null)); }
public void NegativeBufferSizeThrows() { AssertExtensions.Throws <ArgumentOutOfRangeException>("bufferSize", () => CreateFileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, -1)); }
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))); }
public void OffsetOf_NotMarshallable_ThrowsArgumentException(Type t, string fieldName) { AssertExtensions.Throws <ArgumentException>(null, () => Marshal.OffsetOf(t, fieldName)); }
public void GetDirectoryName_ArgumentExceptions(string path) { // In NetFX we normalize and check invalid path chars AssertExtensions.Throws <ArgumentException>("path", null, () => Path.GetDirectoryName(path)); }
public void Ctor_EmptyName_ThrowsArgumentException() { AssertExtensions.Throws <ArgumentException>("name", null, () => new RegionInfo("")); }
public void IsPathRooted_ArgumentExceptions(string path) { // In NetFX we check invalid path chars AssertExtensions.Throws <ArgumentException>("path", null, () => Path.IsPathRooted(path)); }
public void Ctor_InvalidName_ThrowsArgumentException(string name) { AssertExtensions.Throws <ArgumentException>("name", () => new RegionInfo(name)); }
public void GetFullPath_NotSupportedColons(string path) { // Throws via our invalid colon filtering (as part of FileIOPermissions) AssertExtensions.ThrowsAny <NotSupportedException, ArgumentException>(() => Path.GetFullPath(path)); }
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)); }
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 }
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)); }
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)); }
public void RemoveAuditRuleSpecific_InvalidObjectAuditRule() { var customObjectSecurity = new CustomDirectoryObjectSecurity(); AssertExtensions.Throws <ArgumentNullException>("rule", () => customObjectSecurity.RemoveAuditRuleSpecific(null)); }
public void Rfc5869DeriveKeyNullIkm() { AssertExtensions.Throws <ArgumentNullException>( "ikm", () => HKDF.DeriveKey(HashAlgorithmName.SHA1, null, 20, Array.Empty <byte>(), Array.Empty <byte>())); }
public void AddAccessRule_InvalidObjectAccessRule() { var customObjectSecurity = new CustomDirectoryObjectSecurity(); AssertExtensions.Throws <ArgumentNullException>("rule", () => customObjectSecurity.AddAccessRule(null)); }
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(""))); }
public void OffsetOf_NoSuchFieldName_ThrowsArgumentException() { AssertExtensions.Throws <ArgumentException>("fieldName", () => Marshal.OffsetOf(typeof(NonExistField), "NonExistField")); AssertExtensions.Throws <ArgumentException>("fieldName", () => Marshal.OffsetOf <NonExistField>("NonExistField")); }