public void CreatePropertyState_StateNotExists_StateCreated()
        {
            // Arrange
            var unitOfWork = new UnitOfWorkMock();
            var service = new PropertyStateService(unitOfWork);
            var property = CreateProperty();
            unitOfWork.GetRepository<Property>().Insert(property);
            unitOfWork.GetRepository<Property>().Insert(property);
            unitOfWork.Save();

            // Act
            service.CreateState(property, "newValue");

            // Assert
            unitOfWork.GetRepository<PropertyState>().Get().Should().Contain(x => x.Value == "newValue");
        }
        public void CreatePropertyState_StateNotExists_NewStateReturned()
        {
            // Arrange
            var unitOfWork = new UnitOfWorkMock();
            var service = new PropertyStateService(unitOfWork);
            var property = CreateProperty();
            unitOfWork.GetRepository<Property>().Insert(property);
            unitOfWork.GetRepository<Property>().Insert(property);
            unitOfWork.Save();

            // Act
            var newState = service.CreateState(property, "newValue");

            // Assert
            newState.Should().Be(unitOfWork.GetRepository<PropertyState>().Get().Last());
        }
        public void CreatePropertyState_StateOfSamePropertyExists_StateHasUniquePropertyStateIndex()
        {
            // Arrange
            var unitOfWork = new UnitOfWorkMock();
            var service = new PropertyStateService(unitOfWork);
            var property = CreateProperty();
            var propertyState = CreatePropertyState(property);
            propertyState.Index = 2;
            unitOfWork.GetRepository<PropertyState>().Insert(propertyState);
            unitOfWork.Save();

            // Act
            service.CreateState(property, "newValue");

            // Assert
            unitOfWork.GetRepository<PropertyState>().Get().Last().Index.Should().Be(3);
        }
Ejemplo n.º 4
0
        public void UserHasPermissions_UserNotOrderedPackage_UserHasNoPermissions()
        {
            // Arrange
            var unitOfWork = new UnitOfWorkMock();
            var user = new User();
            var userProfile = new UserProfile {User = user};
            var package = new ContentPackage {Owner = new User()};
            unitOfWork.GetRepository<User>().Insert(user);
            unitOfWork.GetRepository<UserProfile>().Insert(userProfile);
            unitOfWork.GetRepository<ContentPackage>().Insert(package);
            unitOfWork.Save();

            // Act
            var financeService = new FinanceService(unitOfWork);
            var userHasPermissions = financeService.UserHasPermissions(user, package);

            // Assert
            userHasPermissions.Should().BeFalse();
        }
        private void InitUnitOfWork(UnitOfWorkMock unitOfWork)
        {
            var property1 = new Property {Name = "property1", Order = 1, ID = 1};
            var property2 = new Property {Name = "property2", Order = 2, ID = 2};

            var state1 = new PropertyState {Property = property1, Value = "state1"};
            var state2 = new PropertyState {Property = property1, Value = "state2"};
            var state3 = new PropertyState {Property = property2, Value = "state3"};
            var state4 = new PropertyState {Property = property2, Value = "state4"};

            property1.States = new List<PropertyState> {state1, state2};
            property2.States = new List<PropertyState> {state3, state4};

            var package1 = new ContentPackage
                           {
                               ID = 1,
                               PropertyStates = new Collection<PropertyState> {state1, state3}
                           };

            var package2 = new ContentPackage
                           {
                               ID = 2,
                               PropertyStates = new Collection<PropertyState> {state2, state4}
                           };

            state1.ContentPackages = new Collection<ContentPackage> {package1};
            state2.ContentPackages = new Collection<ContentPackage> {package2};
            state3.ContentPackages = new Collection<ContentPackage> {package1};
            state4.ContentPackages = new Collection<ContentPackage> {package2};

            unitOfWork.GetRepository<Property>().Insert(property1);
            unitOfWork.GetRepository<Property>().Insert(property2);

            unitOfWork.GetRepository<PropertyState>().Insert(state1);
            unitOfWork.GetRepository<PropertyState>().Insert(state2);
            unitOfWork.GetRepository<PropertyState>().Insert(state3);
            unitOfWork.GetRepository<PropertyState>().Insert(state4);

            unitOfWork.GetRepository<ContentPackage>().Insert(package1);
            unitOfWork.GetRepository<ContentPackage>().Insert(package2);

            unitOfWork.Save();
        }
        public void CreatePropertyState_StateOfSamePropertyNotExists_StateHasUniquePropertyStateIndex()
        {
            // Arrange
            var unitOfWork = new UnitOfWorkMock();
            var service = new PropertyStateService(unitOfWork);
            var propertyState = CreatePropertyState(CreateProperty(id: 1));
            unitOfWork.GetRepository<PropertyState>().Insert(propertyState);
            unitOfWork.Save();

            // Act
            service.CreateState(CreateProperty(id: 2), "newValue");

            // Assert
            unitOfWork.GetRepository<PropertyState>().Get().Should().Contain(x => x.Index == 1);
        }
        public void GetState_StateExists_StateReturned()
        {
            // Arrange
            var unitOfWork = new UnitOfWorkMock();
            var propertyStateService = new PropertyStateService(unitOfWork);
            var property = CreateProperty();
            var propertyState = CreatePropertyState(property);
            unitOfWork.GetRepository<PropertyState>().Insert(propertyState);
            unitOfWork.Save();

            // Act
            var state = propertyStateService.GetState(property.ID, propertyState.Value);

            // Assert
            state.Should().Be(propertyState);
        }