// Make sure we're not a fake principal
CheckFakePrincipal();
- if (context.ContextType == ContextType.Machine || _ctx.ContextType == ContextType.Machine)
- {
- throw new InvalidOperationException(SR.SaveToNotSupportedAgainstMachineStore);
- }
// We must have a PrincipalContext to save into. This should always be the case, unless we're unpersisted
// and they never set a PrincipalContext.
if (context == null)
throw new InvalidOperationException(SR.NullArguments);
}
+ if (context.ContextType == ContextType.Machine || _ctx.ContextType == ContextType.Machine)
+ {
+ throw new InvalidOperationException(SR.SaveToNotSupportedAgainstMachineStore);
+ }
+
// If the user is trying to save to the same context we are already set to then just save the changes
if (context == _ctx)
{
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Collections.Generic;
using System.Security.Principal;
using Xunit;
}
}
+ [Theory]
+ [MemberData(nameof(TestDebuggerAttributes_Inputs))]
+ public void Save_ThrowsInvalidOperationException(PrincipalContext context)
+ {
+ if (DomainContext == null)
+ {
+ return;
+ }
+
+ using (Principal principal = CreateExtendedPrincipal(DomainContext, Guid.NewGuid().ToString()))
+ {
+ Assert.Throws<InvalidOperationException>(() => principal.Save(context));
+ }
+ }
+
+ public static IEnumerable<object[]> TestDebuggerAttributes_Inputs()
+ {
+ yield return new object[] { null };
+ yield return new object[] { new PrincipalContext(ContextType.Machine) };
+ }
+
public abstract Principal CreatePrincipal(PrincipalContext context, string name);
public abstract Principal CreateExtendedPrincipal(PrincipalContext context, string name);