예제 #1
0
 public void AddRsvpItem(RSVP rsvp)
 {
     using (var context = new WeddingContext())
     {
         context.Rsvps.Add(rsvp);
         context.SaveChanges();
     }
 }
예제 #2
0
        public void AddRsvp_NoValueForName_EntityWrapperAddRsvpItemNotCalled()
        {
            // setup
            var rsvp = new RSVP { Email = "*****@*****.**" };

            // action
            _postHelper.AddRsvp(rsvp);

            // assert
            _entityWrapper.DidNotReceive().AddRsvpItem(Arg.Any<RSVP>());
        }
예제 #3
0
        public void AddRsvp_NoValueForName_ReturnsErrorMessage()
        {
            // setup
            var rsvp = new RSVP {Email = "*****@*****.**"};

            // action
            var msg = _postHelper.AddRsvp(rsvp);

            // assert
            Assert.AreEqual(Constants.ErrorMessage, msg);
        }
예제 #4
0
        public void AddRsvp_NoValueForEmail_ReturnsErrorMessage()
        {
            // setup
            var rsvp = new RSVP { Name = "Mister Test" };

            // action
            var msg = _postHelper.AddRsvp(rsvp);

            // assert
            Assert.AreEqual(Constants.ErrorMessage, msg);
        }
예제 #5
0
        public void AddRsvp_CorrectData_ReturnsSuccessMessage()
        {
            // setup
            var rsvp = new RSVP { Name = "Mister Test", Email = "*****@*****.**" };

            // action
            var msg = _postHelper.AddRsvp(rsvp);

            // assert
            Assert.AreEqual(Constants.SuccessMessage, msg);
        }
예제 #6
0
        public void AddRsvp_CorrectData_CallingEntityWrapperAddRsvpItem()
        {
            // setup
            var rsvp = new RSVP {Name="Mister Test", Email="*****@*****.**"};

            // action
            _postHelper.AddRsvp(rsvp);

            // assert
            _entityWrapper.Received().AddRsvpItem(Arg.Any<RSVP>());
        }
예제 #7
0
        public string AddRsvp(RSVP rsvp)
        {
            if (!IsValid(rsvp)) return Constants.ErrorMessage;
            
            rsvp.Email = rsvp.Email.ToLower();

            try
            {
                _entityWrapper.AddRsvpItem(rsvp);
            }
            catch (Exception)
            {
                return Constants.ErrorMessage;
            }

            return Constants.SuccessMessage;
        }
예제 #8
0
        public void AddRsvp_NoValueForEmail_EntityWrapperAddRsvpItemNotCalled()
        {
            // setup
            var rsvp = new RSVP { Name = "Mister Test" };

            // action
            _postHelper.AddRsvp(rsvp);

            // assert
            _entityWrapper.DidNotReceive().AddRsvpItem(Arg.Any<RSVP>());
        }
예제 #9
0
        public void AddRsvp_PoorlyFormattedEmail_EmailIsFormattedProperly()
        {
            // setup
            var rsvp = new RSVP { Name = "Mister Test", Email = "*****@*****.**"};

            // action
            _postHelper.AddRsvp(rsvp);

            // assert
            Assert.AreEqual("*****@*****.**", rsvp.Email);
        }
예제 #10
0
 public bool IsValid(RSVP rsvp)
 {
     return rsvp != null &&
            !IsNullOrWhiteSpace(rsvp.Name) &&
            !IsNullOrWhiteSpace(rsvp.Email);
 }