Ejemplo n.º 1
0
        public async Task ShouldReturnInfo_When_Correct_Parrameters_Are_Passed()
        {
            const int    contactId = 1;
            const string message   = "message";
            const string email     = "*****@*****.**";

            var contactInfo = new ContactInfo()
            {
                ContactInfoId = contactId,
                Email         = email,
                Message       = message
            };

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.PostAsync <ContactInfo>(It.IsAny <string>(), It.IsAny <ContactInfo>(), It.IsAny <string>()))
            .Returns(Task.FromResult <ContactInfo>(contactInfo));

            var contactService = new ContactDataService(requestProviderMock.Object);

            var contactServiceResult = await contactService.AddContactInfoAsync(message, email);

            Assert.IsNotNull(contactServiceResult);
            Assert.AreEqual(contactId, contactServiceResult.ContactInfoId);
            Assert.AreEqual(message, contactServiceResult.Message);
            Assert.AreEqual(email, contactServiceResult.Email);
        }
Ejemplo n.º 2
0
        public void Throws_When_Message_Is_Invalid(string message)
        {
            const int    contactId = 1;
            const string email     = "*****@*****.**";

            var contactInfo = new ContactInfo()
            {
                ContactInfoId = contactId,
                Email         = email,
                Message       = message
            };

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.PostAsync <ContactInfo>(It.IsAny <string>(), It.IsAny <ContactInfo>(), It.IsAny <string>()))
            .Returns(Task.FromResult <ContactInfo>(contactInfo));

            var contactService = new ContactDataService(requestProviderMock.Object);

            Assert.ThrowsAsync <ContactDataException>(
                async() => await contactService.AddContactInfoAsync(message, email));
        }