public void Query_WithSpecification_ShouldReturnFilteredQueryFromWorkplace()
        {
            //Arrange
            var list = new List <ComponentInterface>
            {
                new Mock <ComponentInterface>().WithId(Guid.NewGuid()).Object,
                new Mock <ComponentInterface>().Object,
                new Mock <ComponentInterface>().Object
            };

            MockWorkplace.Setup(x => x.Query <ComponentInterface>())
            .Returns(list.AsQueryable());
            Repository = CreateRepositoryWithWorkplace(MockWorkplace.Object);
            Expression <Func <ComponentInterface, bool> > specExpression = x => x.Id != Guid.Empty;

            //Act
            var result = Repository.Query(
                new TestPersistenceAwareSpec <ComponentInterface>(specExpression)).ToList();

            //Assert
            Assert.That(result.Count == list.Where(specExpression.Compile()).Count());
            foreach (var componentInterface in result)
            {
                Assert.That(list.Where(specExpression.Compile()).Contains(componentInterface));
            }
        }
        public void Query_ValidComponentType_ShouldQueryComponentsOfSpecifiedTypes()
        {
            //Arrange
            const ComponentType requestType = ComponentType.Motherboard;
            var components = new List <PCComponent>
            {
                DomainObjectsCreator.CreateComponent(0, requestType),
                DomainObjectsCreator.CreateComponent(0, ComponentType.HardDiskDrive),
                DomainObjectsCreator.CreateComponent(0, requestType),
                DomainObjectsCreator.CreateComponent(0, ComponentType.PowerSupply)
            };

            MockWorkplace.Setup(x => x.Query <PCComponent>())
            .Returns(components.AsQueryable());

            //Act
            var queriesComponents = Repository.Query(requestType).ToList();

            //Assert
            Assert.That(queriesComponents.Count == 2);
            Assert.That(queriesComponents.All(x => x.Type == requestType));
        }
Пример #3
0
        public void FindPublishedConfigurations_NotEmptyName_ShouldReturnPublishedConfigurationsWithSpecifiedName()
        {
            //Arrange
            var requestedName      = NamesGenerator.ConfigurationName();
            var configurationsList = new List <PCConfiguration>
            {
                new Mock <PCConfiguration>().Object.WithName(NamesGenerator.ConfigurationName(1)),
                new Mock <PCConfiguration>().Object.WithName(requestedName),
                new Mock <PCConfiguration>().Object.WithName(requestedName),
                new Mock <PCConfiguration>().Object.WithName(NamesGenerator.ConfigurationName(2))
            };

            configurationsList[1].MoveToStatus(PCConfigurationStatus.Published);
            configurationsList[3].MoveToStatus(PCConfigurationStatus.Published);
            MockWorkplace.Setup(x => x.Query <PCConfiguration>()).Returns(configurationsList.AsQueryable());

            //Act
            var retrievedConfigurations = Repository.FindPublishedConfigurations(requestedName).ToList();

            //Assert
            Assert.That(retrievedConfigurations.Count == 1);
            Assert.That(retrievedConfigurations.First().Status == PCConfigurationStatus.Published);
            Assert.That(retrievedConfigurations.First().Name == requestedName);
        }