コード例 #1
0
        public VersionDetail IncrementVersion(IVersionRequest request)
        {
            var versions = GetVersions(request);

            var versionList = versions.OrderBy(x => new Version(x.Version.Major, x.Version.Minor)).Reverse();

            VersionSimple version = null;

            if (versionList.Count() == 0)
            {
                version.CreateIncrement(request);
            }
            else
            {
                version = versionList.First().Version;
                version.CalculateIncrement(request);
            }

            var versionDetail = new VersionDetail
            {
                Version     = version,
                CreatedDate = DateTime.Now,
                Product     = new Product
                {
                    Id = request.ProductId
                }
            };

            var created = _repository.Add(versionDetail);

            return(created);
        }
コード例 #2
0
        public void GetVersionMajorMinor()
        {
            var versionDetail = new VersionRequest()
            {
                ProductId = 1,
                Major     = 8,
                Minor     = 2
            };

            var repository = new Mock <IVersionDetailRepository>();

            repository.Setup(x => x.GetByProductId(versionDetail.ProductId))
            .Returns(VersionDetails
                     .Where(x => x.Product.Id == versionDetail.ProductId &&
                            x.Version.Major == versionDetail.Major));

            var service = new VersionService(repository.Object);

            var version = service.GetVersions(versionDetail);

            version.Count().Should().Be(1);
            var expectedVersion = new VersionSimple(8, 2, 100, 0);

            version.First().Version.Major.Should().Be(expectedVersion.Major);
            version.First().Version.Minor.Should().Be(expectedVersion.Minor);
            version.First().Version.Build.Should().Be(expectedVersion.Build);
            version.First().Version.Revision.Should().Be(expectedVersion.Revision);
        }
コード例 #3
0
            public void WithMinorArgumentException()
            {
                var version = new VersionSimple(8, 3, 0, 0);

                Action result = () => version.CalculateIncrement(new VersionRequest
                {
                    ProductId = 1,
                    Minor     = 3
                });

                result.Should().Throw <ArgumentException>();
            }
コード例 #4
0
            public void JustProductId()
            {
                var version = new VersionSimple(8, 3, 0, 0);

                var calculatedVersion = version.CalculateIncrement(new VersionRequest
                {
                    ProductId = 1
                });

                calculatedVersion.Major.Should().Be(9);
                calculatedVersion.Minor.Should().Be(0);
                calculatedVersion.Build.Should().Be(0);
                calculatedVersion.Revision.Should().Be(0);
            }
コード例 #5
0
            public void WithMajor()
            {
                var version = new VersionSimple(8, 2, 0, 0);

                var calculatedVersion = version.CalculateIncrement(new VersionRequest
                {
                    ProductId = 1,
                    Major     = 8
                });

                calculatedVersion.Major.Should().Be(8);
                calculatedVersion.Minor.Should().Be(3);
                calculatedVersion.Build.Should().Be(0);
                calculatedVersion.Revision.Should().Be(0);
            }
コード例 #6
0
        public void AddItemToVersion()
        {
            var versionDetail = new VersionRequest()
            {
                ProductId = 1,
                Major     = 8,
                Minor     = 2
            };

            var addResult = new VersionDetail
            {
                Id      = 1,
                Version = new VersionSimple
                {
                    Major    = 8,
                    Minor    = 2,
                    Build    = 101,
                    Revision = 0
                },
                CreatedDate = DateTime.Now
            };

            var repository = new Mock <IVersionDetailRepository>();

            repository.Setup(x => x.GetByProductId(versionDetail.ProductId))
            .Returns(VersionDetails
                     .Where(x => x.Product.Id == versionDetail.ProductId &&
                            x.Version.Major == versionDetail.Major));

            repository.Setup(x => x.Add(It.IsAny <VersionDetail>()))
            .Returns(addResult);

            var service = new VersionService(repository.Object);

            var version = service.IncrementVersion(versionDetail);

            var expectedVersion = new VersionSimple(8, 2, 101, 0);

            version.Version.Major.Should().Be(expectedVersion.Major);
            version.Version.Minor.Should().Be(expectedVersion.Minor);
            version.Version.Build.Should().Be(expectedVersion.Build);
            version.Version.Revision.Should().Be(expectedVersion.Revision);
        }
コード例 #7
0
        public static VersionSimple CalculateIncrement(this VersionSimple version, IVersionRequest request)
        {
            VersionSimple incrementedVersion = version;

            if (!request.Major.HasValue && request.Minor.HasValue)
            {
                throw new ArgumentException("Cannot pass a Minor version without Major version");
            }

            if (request.Major.HasValue && request.Minor.HasValue)
            {
                incrementedVersion = incrementedVersion.IncrementBuild();
            }
            else if (request.Major.HasValue && !request.Minor.HasValue)
            {
                incrementedVersion = incrementedVersion.IncrementMinor();
            }
            else
            {
                incrementedVersion = incrementedVersion.IncrementMajor();
            }

            return(incrementedVersion);
        }
コード例 #8
0
        public static VersionSimple CreateIncrement(this VersionSimple version, IVersionRequest request)
        {
            VersionSimple incrementedVersion = version;

            if (!request.Major.HasValue && request.Minor.HasValue)
            {
                throw new ArgumentException("Cannot pass a Minor version without Major version");
            }

            if (request.Major.HasValue && !request.Minor.HasValue)
            {
                incrementedVersion = new VersionSimple(request.Major.Value, 0, 0, 0);
            }
            else if (request.Major.HasValue && request.Minor.HasValue)
            {
                incrementedVersion = new VersionSimple(request.Major.Value, request.Minor.Value, 0, 0);
            }
            else
            {
                incrementedVersion = new VersionSimple(1, 0, 0, 0);
            }

            return(incrementedVersion);
        }
コード例 #9
0
        public static VersionSimple IncrementMajor(this VersionSimple version)
        {
            var newVersion = new VersionSimple(version.Major + 1, 0, 0, 0);

            return(newVersion);
        }
コード例 #10
0
        public static VersionSimple IncrementRevision(this VersionSimple version)
        {
            var newVersion = new VersionSimple(version.Major, version.Minor, version.Build, version.Revision + 1);

            return(newVersion);
        }
コード例 #11
0
        public static VersionSimple IncrementBuild(this VersionSimple version)
        {
            var newVersion = new VersionSimple(version.Major, version.Minor, version.Build + 1, 0);

            return(newVersion);
        }