Example #1
0
        public async Task TestMethod_Can_Not_Signup_A_Person_With_Too_Long()
        {
            ISignup     signup      = new SignMeUp();
            string      random      = Guid.NewGuid().ToString();
            SignupInput signupInput = new SignupInput
            {
                FirstName  = "FirstNameFirstName",
                LastName   = "LastNameLastNameLastName  ",
                Email      = "EmailEmailEmailEmailEmailEmailEmailEmailEmailEmailEmail",
                FunEventId = 1,
                Comments   =
                    "I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids.I will bring my two kids."
            };
            var signupResult = await signup.Add(signupInput);

            Assert.IsTrue(signupResult.Status == OperationStatus.ErrorsWhenAdding);
            Assert.IsTrue(signupResult.Errors.Count == 4);

            Assert.IsTrue(signupResult.Errors[0].ErrorType == ErrorType.DataInvalid);
            Assert.IsTrue(signupResult.Errors[0].DetailError == "First Name is more than 10 letters");
            Assert.IsTrue(signupResult.Errors[0].MembershipName == "FirstName");

            Assert.IsTrue(signupResult.Errors[1].ErrorType == ErrorType.DataInvalid);
            Assert.IsTrue(signupResult.Errors[1].DetailError == "Last Name is more than 10 letters");
            Assert.IsTrue(signupResult.Errors[1].MembershipName == "LastName");

            Assert.IsTrue(signupResult.Errors[2].ErrorType == ErrorType.DataInvalid);
            Assert.IsTrue(signupResult.Errors[2].DetailError == "Email is more than 30 letters");
            Assert.IsTrue(signupResult.Errors[2].MembershipName == "Email");

            Assert.IsTrue(signupResult.Errors[3].ErrorType == ErrorType.DataInvalid);
            Assert.IsTrue(signupResult.Errors[3].DetailError == "Comments is more than 30 letters");
            Assert.IsTrue(signupResult.Errors[3].MembershipName == "Comments");
        }
Example #2
0
        public async Task TestMethod_Can_Not_Signup_With_Empty_Input()
        {
            ISignup signup       = new SignMeUp();
            var     signupResult = await signup.Add(null);

            Assert.IsTrue(signupResult.Status == OperationStatus.ErrorsWhenAdding);
            Assert.IsTrue(signupResult.Errors.Count == 1);
            Assert.IsTrue(signupResult.Errors[0].ErrorType == ErrorType.EmptyEntry);
            Assert.IsTrue(signupResult.Errors[0].DetailError == "No Signu up Info Provided.");
        }
Example #3
0
        public async Task TestMethod_Can_Not_SignUp_Same_Email_Twice_Under_Same_Event()
        {
            ISignup     signup      = new SignMeUp();
            string      random      = Guid.NewGuid().ToString();
            SignupInput signupInput = new SignupInput {
                FirstName = "Yan", LastName = "Wang", Email = random.Substring(1, 10) + "@email.com", FunEventId = 100
            };
            var signupResult = await signup.Add(signupInput);

            Assert.IsTrue(signupResult.Status == OperationStatus.Added);
            Assert.IsTrue(signupResult.Errors.Count == 0);
            Assert.IsTrue(signupResult.ResourceId == string.Format("{0}###{1}", signupInput.Email, signupInput.FunEventId));

            // Try again
            var signupResultAgain = await signup.Add(signupInput);

            Assert.IsTrue(signupResultAgain.Status == OperationStatus.DuplicatedWhenAdding);
            Assert.IsTrue(signupResultAgain.Errors.Count == 0);
            Assert.IsTrue(signupResultAgain.ResourceId == string.Format("{0}###{1}", signupInput.Email, signupInput.FunEventId));
        }
Example #4
0
        public async Task TestMethod_Can_Signup_A_Person_Successfully()
        {
            ISignup     signup      = new SignMeUp();
            string      random      = Guid.NewGuid().ToString();
            SignupInput signupInput = new SignupInput {
                FirstName = "Yan", LastName = "Wang", Email = random.Substring(1, 10) + "@email.com", FunEventId = 100, Comments = "I will bring my two kids."
            };
            var signupResult = await signup.Add(signupInput);

            Assert.IsTrue(signupResult.Status == OperationStatus.Added);
            Assert.IsTrue(signupResult.Errors.Count == 0);
            Assert.IsTrue(signupResult.ResourceId == string.Format("{0}###{1}", signupInput.Email, signupInput.FunEventId));
        }
Example #5
0
        public async Task TestMethod_Can_Not_Signup_Person_With_Not_Existing_Event()
        {
            int         notExistingEvent = int.MaxValue - 1;
            ISignup     signup           = new SignMeUp();
            string      random           = Guid.NewGuid().ToString();
            SignupInput signupInput      = new SignupInput {
                FirstName = "Yan", LastName = "Wang", Email = random.Substring(1, 10) + "@email.com", FunEventId = notExistingEvent
            };
            var signupResult = await signup.Add(signupInput);

            Assert.IsTrue(signupResult.Status == OperationStatus.ErrorsWhenAdding);
            Assert.IsTrue(signupResult.Errors.Count == 1);
            Assert.IsTrue(signupResult.Errors[0].ErrorType == ErrorType.DataInvalid);
            Assert.IsTrue(signupResult.Errors[0].MembershipName == "FunEventId");
            Assert.IsTrue(signupResult.Errors[0].DetailError == "Event is not Existing");
        }
Example #6
0
        public async Task TestMethod_Can_Signup_A_Person_Successfully_OnlyOnce_WhenTryingToRepeat()
        {
            ISignup signup = new SignMeUp();
            List <Task <SignupResult> > tasks = new List <Task <SignupResult> >();
            string      random      = Guid.NewGuid().ToString();
            SignupInput signupInput = new SignupInput {
                FirstName = "ONLY", LastName = "ONE", Email = random.Substring(1, 10) + "@email.com", FunEventId = 100, Comments = "ONly ONe"
            };

            for (int i = 0; i < 100; i++)
            {
                var task = signup.Add(signupInput);
                tasks.Add(task);
            }

            await Task.WhenAll(tasks);

            int total = 0;
            int dup   = 0;

            foreach (var t in tasks)
            {
                if (t.Result.Status == OperationStatus.Added)
                {
                    total++;
                }
                else if (t.Result.Status == OperationStatus.DuplicatedWhenAdding)
                {
                    dup++;
                }
                else
                {
                }
            }

            Assert.IsTrue(total == 1);
            Assert.IsTrue(dup == 99);
        }
Example #7
0
        private static async Task InitializeAsync()
        {
            ISignup  signup = new SignMeUp();
            SignMeUp help   = signup as SignMeUp;

            help.TestingHelper();

            ExpectedList = new List <SignupInput>();
            List <Task <SignupResult> > tasks = new List <Task <SignupResult> >();

            // Signup - Diff Persons sign up same events
            for (int i = 0; i <= 50; i++)
            {
                // Create one person.
                string      random      = Guid.NewGuid().ToString();
                SignupInput signupInput = new SignupInput
                {
                    FirstName = random.Substring(1, 3) + UnitTest_Signup.FirstName + random.Substring(3, 3),
                    LastName  = random.Substring(6, 3) + UnitTest_Signup.LastName + random.Substring(10, 3),
                    Email     = random.Substring(1, 10) + "@email.com",
                    Comments  = ""
                };

                // Signup - Same person signs up 3 events.
                SignupInput signupInput1 = new SignupInput
                {
                    FirstName = signupInput.FirstName,
                    LastName  = signupInput.LastName,
                    Email     = signupInput.Email,
                    Comments  = signupInput.Comments
                };
                ExpectedList.Add(signupInput1);
                signupInput1.FunEventId = 100;
                var task1 = signup.Add(signupInput1);
                tasks.Add(task1);

                SignupInput signupInput2 = new SignupInput
                {
                    FirstName = signupInput.FirstName,
                    LastName  = signupInput.LastName,
                    Email     = signupInput.Email,
                    Comments  = signupInput.Comments
                };
                ExpectedList.Add(signupInput2);
                signupInput2.FunEventId = 101;
                var task2 = signup.Add(signupInput2);
                tasks.Add(task2);

                SignupInput signupInput3 = new SignupInput
                {
                    FirstName = signupInput.FirstName,
                    LastName  = signupInput.LastName,
                    Email     = signupInput.Email,
                    Comments  = signupInput.Comments
                };
                ExpectedList.Add(signupInput3);
                signupInput3.FunEventId = 102;
                var task3 = signup.Add(signupInput3);
                tasks.Add(task3);
            }

            await Task.WhenAll(tasks);
        }