public void ValidUserTest() { // arrange var employee = new Employee(); // good values - can only be alphanumeric with underscores var goodUser = "******"; var goodNoUnder = "michaelrhodes"; var goodNumber = "michael1234"; var goodCapital = "MichaelRhodes"; // bad values - no spaces, cannot be empty, cannot be null, no special chars var badSpace = "Michael Rhodes"; var badEmpty = ""; string badNull = null; var badSpecial = "Michael@"; var throwaway = new CreationException(); var validGood = employee.ValidUser(goodUser, throwaway); var validUnder = employee.ValidUser(goodNoUnder, throwaway); var validNumber = employee.ValidUser(goodNumber, throwaway); var validCapital = employee.ValidUser(goodCapital, throwaway); var invalidSpace = employee.ValidUser(badSpace, throwaway); var invalidEmpty = employee.ValidUser(badEmpty, throwaway); var invalidNull = employee.ValidUser(badNull, throwaway); var invalidSpecial = employee.ValidUser(badSpecial, throwaway); Assert.IsTrue(validGood); Assert.IsTrue(validCapital); Assert.IsTrue(validNumber); Assert.IsTrue(validUnder); Assert.IsFalse(invalidEmpty); Assert.IsFalse(invalidSpace); Assert.IsFalse(invalidSpecial); Assert.IsFalse(invalidNull); }
public int Modify( string userName, string password, string confPass, string permission, Employee emp) { Tuple <string, Permission>[] perms = Employee.GetPermissions(); // container exception for all then errors in the modification CreationException exception = new CreationException(); bool goodPass = true; if (!string.IsNullOrWhiteSpace(password)) { goodPass = emp.ValidPass(password, confPass, exception); } bool goodUser = emp.ValidUser(userName, exception); // match the permission string from the view with the correct // permission on the Permission Enum Permission suppliedPerm = (from perm in perms where perm.Item1 == permission select perm.Item2).FirstOrDefault(); // default value is 0 or "None" if (suppliedPerm == Permission.None) { exception.AddError( "Invalid selected permission", "The permission provided wasn't any of Manager, " + "Enrollee Specialist, HSP Specialist, Plan Admin, or" + " Accountant"); } if (exception.IsProblem) { throw exception; } if (!string.IsNullOrWhiteSpace(password)) { emp.SetSecurePass(password); } emp.NewName = userName; emp.Permission = suppliedPerm; int id = Mgr.UpdateEmployee(emp); return(id); }
public void ValidPassTest() { var employee = new Employee(); // good values - needs to be more than 8 characters and conf needs // to match original var goodPass = "******"; var goodConf = "michael_rhodes_"; // bad values - less than 8 characters and null string badNull = null; var badLen = "michael"; var badConf = "michael-rhodes-"; var throwaway = new CreationException(); var validPass = employee.ValidPass(goodPass, goodConf, throwaway); var invalidMismatch = employee.ValidPass(goodPass, badConf, throwaway); var invalidLen = employee.ValidPass(badLen, badLen, throwaway); var invalidNull = employee.ValidPass(badNull, badNull, throwaway); Assert.IsTrue(validPass); Assert.IsFalse(invalidMismatch); Assert.IsFalse(invalidNull); Assert.IsFalse(invalidLen); }
public override bool ValidUser(string userName, CreationException exception) { throw new NotImplementedException(); }
public override bool ValidPass(string password, string confPass, CreationException exception) { throw new NotImplementedException(); }
public TestDataGeneratorEdgeCaseSpeck() { Specify(x => TestDataGenerator.Create <ClassWithList> (MaxRecursionDepth, null)) .Case("Properties Are Initialized", _ => _ .Given(ConfigurationContext(cfg => cfg.UseDefaults(false) .For <ClassWithList> ().AddProvider(new DefaultInstanceValueProvider <ClassWithList> ()) .For <IList <int> > ().AddProvider(f => new List <int> { 0, 1, 2, 3 }))) .It("initialized first list correctly", x => x.Result.IntegerList.Should().BeEquivalentTo(new[] { 0, 1, 2, 3 }))); Specify(x => TestDataGenerator.Create <ClassWithInterfacedMembers> (MaxRecursionDepth, null)) .Case("Interfaced Properties Are Initialized", _ => _ .Given(ConfigurationContext(cfg => cfg.UseDefaults(false) .For <ClassWithInterfacedMembers> ().AddProvider(new DefaultInstanceValueProvider <ClassWithInterfacedMembers> ()) .For <InterfacedClass> ().AddProvider(new DefaultInstanceValueProvider <InterfacedClass> ()) .For <IInterface> ().Select(i => i.Name).AddProvider(ctx => "IInterfaced - Name") .For <DerivedInterfacedClass> ().Select(d => d.Value).AddProvider(ctx => "My Value") .For <DerivedInterfacedClass> ().Select(d => d.Name).AddProvider(ctx => "Derived + " + ctx.GetPreviousValue()))) .It("initialized interfaced class according to interface registration", x => x.Result.InterfacedClass.Name.Should().Be("IInterfaced - Name")) .It("initialized derived interfaced class according to interface registration", x => x.Result.DerivedInterfacedClass.Name.Should().Be("Derived + IInterfaced - Name")) .It("initialized derived interfaced class value according to it's registration", x => x.Result.DerivedInterfacedClass.Value.Should().Be("My Value"))); Specify(x => "empty") .Case("should throw exception for methods", _ => _ .Given(ConfigurationContext(c => c.For <ClassWithVariousMembers> ().Select(y => y.PublicMethod()).AddProvider(dummy => ""))) .It("ex", x => CreationException.Should().BeOfType <NotSupportedException> ()) .It("ex", x => CreationException.Message.Should().Be("Empty chains / Non-member chains are not supported, please use AddProvider<T>()"))) .Case("should throw exception for types", _ => _ .Given(ConfigurationContext(c => c.For <ClassWithVariousMembers> ().Select(y => y).AddProvider(dummy => null))) .It("ex", x => CreationException.Should().BeOfType <NotSupportedException> ()) .It("ex", x => CreationException.Message.Should().Be("Empty chains / Non-member chains are not supported, please use AddProvider<T>()"))); Specify(x => TestDataGenerator.Create <ClassWithVariousMembers> (MaxRecursionDepth, null)) .Case("should throw exception for setting the value of a get only member", _ => _ .Given(ConfigurationContext(c => c.For <ClassWithVariousMembers> ().Select(y => y.GetOnlyProperty).AddProvider(dummy => "content"))) .It("GetOnlyProperty should be null", x => x.Result.GetOnlyProperty.Should().BeNull())); Specify(x => TestDataGenerator.Create <BaseClassWithProtectedProperty> (MaxRecursionDepth, null)) .Case("should use value provider for base type OverrideMe property and ignore sub type", _ => _ .Given(NewPropertiesContext()) .It("it assigns correct value", x => x.Result.OverrideMe.Should().Be("BaseValue"))); Specify(x => TestDataGenerator.Create <ClassOveridingPropertyWithNewType> (MaxRecursionDepth, null)) .Case("should use value provider for sub type and ignore base type", _ => _ .Given(NewPropertiesContext()) .It("it assigns correct value", x => x.Result.OverrideMe.Should().Be(103))); Specify(x => TestDataGenerator.Create <ClassOveridingPropertyWithNewType> (MaxRecursionDepth, null)) .Case("should ignore base type and use generic int provider", _ => _ .Given(NewPropertiesBaseClassAndFixedInt()) .It("it uses generic int provider", x => x.Result.OverrideMe.Should().Be(3))); Specify(x => TestDataGenerator.Create <ClassOveridingPropertyWithNewType> (MaxRecursionDepth, null)) .Case("when using previous value should ignore base type", _ => _ .Given(NewPropertiesContextUsingPreviousValue()) .It("it ignores base type and uses generic int provider", x => x.Result.OverrideMe.Should().Be(4))); Specify(x => TestDataGenerator.Create <ClassAddingAttributes> (MaxRecursionDepth, null)) .Case("should fill property with last added provider", _ => _ .Given(AttributeFillerContext()) .It("it assigns correct value", x => x.Result.SomeAttributedProperty.Should().Be("Subclass2"))); Specify(x => TestDataGenerator.Create <ClassAddingAttributes> (MaxRecursionDepth, null)) .Case("should fill property with other subclass attribute", _ => _ .Given(AttributeConcreteForOtherContext()) .It("it assigns correct value", x => x.Result.SomeAttributedProperty.Should().Be("Subclass1"))); Specify(x => TestDataGenerator.Create <ClassWithoutAttribute> (MaxRecursionDepth, null)) .Case("should fill property with previous provider value", _ => _ .Given(AttributeMixedContext()) .It("it assigns correct value", x => x.Result.PropertyWithoutAttribute.Should().Be("Some value"))); Specify(x => TestDataGenerator.Create <ClassWithoutAttribute> (MaxRecursionDepth, null)) .Case("should throw exception because of missing provider", _ => _ .Given(AttributeMixedOtherWayContext()) .ItThrows(typeof(NotSupportedException), "Could not auto-fill Farada.TestDataGeneration.IntegrationTests.TestDomain.ClassWithoutAttribute " + "(member PropertyWithoutAttribute). Please provide a value provider") .ItThrowsInner(typeof(MissingValueProviderException), "Tried to call previous provider on " + "'Farada.TestDataGeneration.IntegrationTests.TestDomain.ClassWithoutAttribute.PropertyWithoutAttribute'" + " but no previous provider was registered. Are you missing a value provider registration?")); }
public abstract bool ValidPass( string password, string confPass, CreationException exception);
public abstract bool ValidUser( string userName, CreationException exception);
/// <summary> /// Check if the information provided by view is valid and if it is: /// create an employee and send back it's id /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="confPass"></param> /// <param name="permission"></param> public int Create( string userName, string password, string confPass, string permission) { // trim any whitespace that can come up with winforms userName = userName.Trim(); password = password.Trim(); confPass = confPass.Trim(); permission = permission.Trim(); var perm = Permission.None; var employee = new Employee(); // if there is an exception with creating the account CreationException except = new CreationException(); switch (permission) { case "Plan Admin": perm = Permission.PlanAdmin; break; case "Enrollee Support": perm = Permission.EnrolleeSupport; break; case "HSP Support": perm = Permission.HSPSupport; break; case "Accountant": perm = Permission.Accountant; break; case "Manager": perm = Permission.Manager; break; default: var msg = "Invalid permission"; var caption = "You pick a permission that wasn't Manager, " + "Accountant, HSP Support, Enrollee Support, or Plan " + "Administrator"; except.AddError(msg, caption); break; } // switch on Permission var validPass = employee.ValidPass(password, confPass, except); var validUser = employee.ValidUser(userName, except); if (except.IsProblem) { throw except; } employee.UserName = userName; employee.SetSecurePass(password); employee.Permission = perm; return(Mgr.SaveEmployee(employee)); }