Esempio n. 1
0
        public async Task ShouldGetCurrentContactDataById()
        {
            var contactToEdit = new AddContact.Command
            {
                Email       = "*****@*****.**",
                Name        = "John Smith",
                PhoneNumber = "555-123-0001"
            };

            var anotherContact = new AddContact.Command
            {
                Email = "*****@*****.**",
                Name  = "Another Contact"
            };

            var response = await Send(contactToEdit);

            await Send(anotherContact);

            var selectedContactId = response.ContactId;

            var result = await Send(new EditContact.Query {
                Id = selectedContactId
            });

            result.ShouldMatch(new EditContact.Command
            {
                Id          = selectedContactId,
                Email       = "*****@*****.**",
                Name        = "John Smith",
                PhoneNumber = "555-123-0001"
            });
        }
Esempio n. 2
0
        public async Task ShouldGetAllContactsSortedByName()
        {
            var ben = new AddContact.Command
            {
                Email       = "*****@*****.**",
                Name        = "Ben",
                PhoneNumber = "555-123-0001"
            };

            var cathy = new AddContact.Command
            {
                Email       = "*****@*****.**",
                Name        = "Cathy",
                PhoneNumber = "555-123-0002"
            };

            var abe = new AddContact.Command
            {
                Email       = "*****@*****.**",
                Name        = "Abe",
                PhoneNumber = "555-123-0003"
            };

            var benId   = (await Send(ben)).ContactId;
            var cathyId = (await Send(cathy)).ContactId;
            var abeId   = (await Send(abe)).ContactId;

            var expectedIds = new[] { benId, cathyId, abeId };

            var query = new ContactIndex.Query();

            var result = await Send(query);

            result.Length.ShouldBe(Count <Contact>());

            result
            .Where(x => expectedIds.Contains(x.Id))
            .ShouldMatch(
                new ContactIndex.ViewModel("Abe", "*****@*****.**", "555-123-0003")
            {
                Id = abeId
            },
                new ContactIndex.ViewModel("Ben", "*****@*****.**", "555-123-0001")
            {
                Id = benId
            },
                new ContactIndex.ViewModel("Cathy", "*****@*****.**", "555-123-0002")
            {
                Id = cathyId
            }
                );
        }
Esempio n. 3
0
        public void ShouldRequireValidEmailAddress()
        {
            var command = new AddContact.Command
            {
                Name        = "John Smith",
                PhoneNumber = "555-123-9999"
            };

            command.ShouldNotValidate("'Email' must not be empty.");

            command.Email = "*****@*****.**";
            command.ShouldValidate();

            command.Email = "test at example dot com";
            command.ShouldNotValidate("'Email' is not a valid email address.");
        }
Esempio n. 4
0
        public async Task ShouldDeleteContactById()
        {
            var contactToDelete = new AddContact.Command
            {
                Email       = "*****@*****.**",
                Name        = "John Smith",
                PhoneNumber = "555-123-0001"
            };

            var contactToPreserve = new AddContact.Command
            {
                Email = "*****@*****.**",
                Name  = "Another Contact"
            };

            var contactToDeleteId   = (await Send(contactToDelete)).ContactId;
            var contactToPreserveId = (await Send(contactToPreserve)).ContactId;

            var countBefore = Count <Contact>();

            await Send(new DeleteContact.Command
            {
                Id = contactToDeleteId
            });

            var countAfter = Count <Contact>();

            countAfter.ShouldBe(countBefore - 1);

            var deletedContact = Query <Contact>(contactToDeleteId);

            deletedContact.ShouldBeNull();

            var remainingContact = Query <Contact>(contactToPreserveId);

            remainingContact.ShouldNotBeNull();
        }
Esempio n. 5
0
        public async Task ShouldSaveChangesToContactData()
        {
            var contactToEdit = new AddContact.Command
            {
                Email       = "*****@*****.**",
                Name        = "John Smith",
                PhoneNumber = "555-123-0001"
            };

            var anotherContact = new AddContact.Command
            {
                Email = "*****@*****.**",
                Name  = "Another Contact"
            };

            var response = await Send(contactToEdit);

            await Send(anotherContact);

            var selectedContactId = response.ContactId;

            await Send(new EditContact.Command
            {
                Id          = selectedContactId,
                Email       = "*****@*****.**",
                Name        = "Patrick Jones",
                PhoneNumber = "555-123-0002"
            });

            var actual = Query <Contact>(selectedContactId);

            actual.ShouldMatch(new Contact("*****@*****.**", "Patrick Jones", "555-123-0002")
            {
                Id = selectedContactId
            });
        }