Пример #1
0
 public InterfaceDeficitInfo(ComponentInterface problemInterface, int deficit,
                             IEnumerable <PCComponent> requiredByComponents)
 {
     ProblemInterface     = problemInterface;
     Deficit              = deficit;
     RequiredByComponents = new List <PCComponent>(requiredByComponents);
 }
Пример #2
0
        public void Save_ValidatorIsSpecified_ShouldThrowExceptionIfEntityIsNotValid()
        {
            //Arrange
            var entity = new ComponentInterface("some name");

            const string propName     = "some prop";
            const string errorMessage = "some error message";
            var          validator    = new Mock <IValidator>();

            validator.Setup(x => x.Validate(entity))
            .Returns(new ValidationResult(new[] { new ValidationFailure(propName, errorMessage) }));
            _validatorFactory.Setup(x => x.GetValidator(typeof(ComponentInterface)))
            .Returns(validator.Object);

            try
            {
                _context.ComponentInterfaces.Add(entity);
                _context.SaveChanges();
                Assert.Fail();
            }
            catch (DbEntityValidationException ex)
            {
                Assert.That(ex.EntityValidationErrors.Count() == 1);
                Assert.That(ex.EntityValidationErrors.First().IsValid == false);
                Assert.That(ex.EntityValidationErrors.First().ValidationErrors.Count == 1);
                Assert.That(ex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage == errorMessage);
                Assert.That(ex.EntityValidationErrors.First().ValidationErrors.First().PropertyName == propName);
            }
        }
        public void Constructor_Called_CanCreateComponentInterface()
        {
            //Arrange
            var name = NamesGenerator.ComponentInterfaceName();
            var componentInterface = new ComponentInterface(name);

            //Assert
            Assert.That(componentInterface.Name, Is.EqualTo(name));
        }
Пример #4
0
 public async Task CreateComponentInterface(ComponentInterfaceVO newInterface)
 {
     await _unitOfWork.Execute(() =>
     {
         var instance = new ComponentInterface(newInterface.Name);
         _repository.Save(instance);
     }, ex =>
     {
         throw new BusinessLogicException(
             string.Format(InterfaceWithNameAlreadyExistsMsg, newInterface.Name), ex);
     });
 }
        public async void CreateComponentInterface_ArgumentNameNotused_ShouldAddNewInterface()
        {
            //Arrange
            var interfaceVO = CreateInterfaceVO();
            ComponentInterface savedInterface = null;

            RepositoryMock.Setup(x => x.Save(It.IsAny <ComponentInterface>()))
            .Callback(new Action <ComponentInterface>(x => { savedInterface = x; }));

            //Act
            await Service.CreateComponentInterface(interfaceVO);

            //Assert
            Assert.That(savedInterface != null);
            Assert.That(savedInterface.Name == interfaceVO.Name);
        }
Пример #6
0
        public void EnumerateContainedSlots_AnyConfiguration_ShouldEnumerateAllSlotsFromComponentAndContainedComponents()
        {
            //Arrange
            const int interfacesCount = 5;
            var       interfaces      = new ComponentInterface[interfacesCount];

            for (var i = 0; i < interfacesCount; i++)
            {
                interfaces[i] = CreateInterface(i).Object;
            }
            var parentComponent = CreateComponent(1)
                                  .WithContainedSlot(interfaces[0])
                                  .WithContainedSlot(interfaces[1])
                                  .WithContainedComponent(
                CreateComponent(2)
                .WithContainedSlot(interfaces[1])
                .WithContainedSlot(interfaces[2])
                .WithContainedComponent(
                    CreateComponent(3).WithContainedSlot(interfaces[4]))
                .WithContainedComponent(
                    CreateComponent(4).WithContainedSlot(interfaces[4])));

            //Act
            var actualInterfaceCounts = parentComponent.EnumerateContainedSlots()
                                        .GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());

            //Assert
            var assertedInterfaceCounts = new Dictionary <ComponentInterface, int>
            {
                { interfaces[0], 1 },
                { interfaces[1], 2 },
                { interfaces[2], 1 },
                { interfaces[4], 2 }
            };

            Assert.That(!actualInterfaceCounts.ContainsKey(interfaces[3]));
            foreach (var assertedCount in assertedInterfaceCounts)
            {
                Assert.That(actualInterfaceCounts[assertedCount.Key], Is.EqualTo(assertedCount.Value));
            }
        }
 public void Save(ComponentInterface componentInterface)
 {
     _workplace.Save(componentInterface);
 }
        public void NameValidationTests(int nameLength, int expectedErrorsCount)
        {
            var entity = new ComponentInterface("".PadLeft(nameLength, '*'));

            AssertErrorsCount(entity, expectedErrorsCount);
        }
Пример #9
0
 private static void AssertInterfacesEqual(ComponentInterface loadedInt, ComponentInterface savedInt)
 {
     Assert.That(loadedInt, Is.Not.Null);
     Debug.Assert(loadedInt != null, "loadedInt != null");
     Assert.That(loadedInt.Name, Is.EqualTo(savedInt.Name));
 }
 private int GetAvailableInterfacesCount(IReadOnlyDictionary <ComponentInterface, int> interfaces,
                                         ComponentInterface arg)
 {
     return(interfaces.ContainsKey(arg) ? interfaces[arg] : 0);
 }