Example #1
0
        public void AddObject()
        {
            // Arrange
            this._dbFixture.TestInitialize();

            const string name = "John Doe";
            const string email = "*****@*****.**";
            const bool isDisabled = false;
            var links = new[] { new Link() { Title = "SomeTitle", Url = @"http://somesite.com/" } };

            User savedData = null;

            var cmd = new CreateUserCommand(name, email, isDisabled, links);

            // Act
            this._unitOfWorkFactory.ExecuteSingleCommand(cmd);

            using (var unitOfWork = this._unitOfWorkFactory.Create())
                savedData = unitOfWork.ResolveQuery<IGetUserByIdQuery>().Execute(cmd.Id, includeLinks: true);

            // Assert
            Assert.NotNull(savedData);
            Assert.Equal(cmd.Id, savedData.Id);
            Assert.Equal(name, savedData.Name);
            Assert.Equal(email, savedData.Email);
            Assert.Equal(isDisabled, savedData.IsDisabled);

            Assert.NotNull(savedData.Links);
            Assert.Equal(links.Count(), savedData.Links.Count());

            var link = savedData.Links.First();
            Assert.Equal(savedData.Id, link.UserProfileId);
            Assert.Equal(links[0].Title, link.Title);
            Assert.Equal(links[0].Url, link.Url);
        }
        public void InsertObjectsIntoRepository(IUnitOfWork unitOfWork, int objectsCount)
        {
            for (var i = 1; i <= objectsCount; ++i) {
                var cmd = new CreateUserCommand(
                    name: $"UserName{i}",
                    email: $"userName{i}@site{i}.com",
                    isDisabled: (i % 2) == 1,
                    links: new[] { new Link() {
                            Title = $"Link{i}",
                            Url = $@"http://site{i}.com"
                    }});

                unitOfWork.ExecuteCommand(cmd);
            }
        }
        public void TestInitialize()
        {
            // Cleanup first
            this.TestCleanup();

            // Set data
            var userCommand = new CreateUserCommand(this.SampleData.Name, this.SampleData.Email, this.SampleData.IsDisabled, null);
            this.UnitOfWorkFactory.ExecuteSingleCommand(userCommand);

            this.SampleData.Id = userCommand.Id;
            this.SampleData.Created = userCommand.Created;

            foreach (Link link in this.SampleData.Links) {
                var linkCommand = new CreateLinkCommand(userCommand.Id, link.Title, link.Url);
                this.UnitOfWorkFactory.ExecuteSingleCommand(linkCommand);
                link.Id = linkCommand.Id;
                link.UserProfileId = userCommand.Id;
            }
        }