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); }
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); }
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>(); }
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); }
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); }
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); }
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); }
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); }
public static VersionSimple IncrementMajor(this VersionSimple version) { var newVersion = new VersionSimple(version.Major + 1, 0, 0, 0); return(newVersion); }
public static VersionSimple IncrementRevision(this VersionSimple version) { var newVersion = new VersionSimple(version.Major, version.Minor, version.Build, version.Revision + 1); return(newVersion); }
public static VersionSimple IncrementBuild(this VersionSimple version) { var newVersion = new VersionSimple(version.Major, version.Minor, version.Build + 1, 0); return(newVersion); }