Пример #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);
 }