-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(issue-213): add unittests and cover 50 percent of c-gen
Merge pull request #214 from live-dev999/live-dev999/issue213
- Loading branch information
Showing
48 changed files
with
1,412 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Services/e-sender/O2NextGen.ESender.Api/Extensions/KeyGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace O2NextGen.ESender.Api.Extensions | ||
{ | ||
public static class KeyGenerator | ||
{ | ||
// private const string ValidChars = "abcdefghjkmnprstwxz2345789"; // Letters and numbers that are not easily mixed with others when reading | ||
private const string ValidChars = "ABCDEFHJKLMNPRSTUWXYZ012345789"; | ||
private static readonly Dictionary<long, bool> ValidCharLookup = new Dictionary<long, bool>(); | ||
private static readonly Random Rnd = new Random(); | ||
|
||
static KeyGenerator() | ||
{ | ||
// Set up a quick lookup dictionary for all valid characters | ||
foreach (var c in ValidChars.ToUpperInvariant()) | ||
ValidCharLookup.Add(c, true); | ||
} | ||
|
||
public static string Generate(int length) | ||
{ | ||
var ret = new char[length]; | ||
for (var i = 0; i < length; i++) | ||
{ | ||
int c; | ||
lock (Rnd) | ||
{ | ||
c = Rnd.Next(0, ValidChars.Length); | ||
} | ||
|
||
ret[i] = ValidChars[c]; | ||
} | ||
|
||
return new string(ret); | ||
} | ||
|
||
public static bool Validate(int maxLength, string key) | ||
{ | ||
if (key.Length > maxLength) | ||
return false; | ||
|
||
foreach (var c in key.ToUpperInvariant()) | ||
if (!ValidCharLookup.ContainsKey(c)) | ||
return false; | ||
return true; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Services/e-sender/O2NextGen.ESender.Api/Extensions/UnixDateExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace O2NextGen.ESender.Api.Extensions | ||
{ | ||
public static class UnixDateExtensions | ||
{ | ||
private static readonly DateTime UnixEpoch = | ||
new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime(); | ||
|
||
public static DateTime ConvertToDateTime(this long seconds, bool isSeconds = true) | ||
{ | ||
return isSeconds ? UnixEpoch.AddSeconds(seconds) : UnixEpoch.AddMinutes(seconds); | ||
} | ||
|
||
public static long ConvertToUnixTime(this DateTime datetime, bool isSeconds = true) | ||
{ | ||
return isSeconds ? (long)(datetime - UnixEpoch).TotalSeconds : (long)(datetime - UnixEpoch).TotalMinutes; | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/Services/e-sender/O2NextGen.ESender.Api/Mappings/BaseMappings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using O2NextGen.ESender.Api.Extensions; | ||
using O2NextGen.ESender.Api.Models; | ||
using O2NextGen.ESender.Business.Models; | ||
|
||
namespace O2NextGen.ESender.Api.Mappings | ||
{ | ||
public class BaseMappings<TViewModel, TModel> | ||
where TViewModel : class, IViewModel | ||
where TModel : class, IBaseModel | ||
{ | ||
public TViewModel ToViewModel(TModel model) | ||
{ | ||
if (model == null) | ||
return null; | ||
|
||
var returnViewModel = Activator.CreateInstance<TViewModel>(); | ||
|
||
returnViewModel.Id = model.Id; | ||
returnViewModel.ExternalId = model.ExternalId; | ||
returnViewModel.AddedDate = model.AddedDate; | ||
returnViewModel.ModifiedDate = model.ModifiedDate; | ||
returnViewModel.DeletedDate = model.DeletedDate; | ||
returnViewModel.IsDeleted = model.IsDeleted; | ||
|
||
return returnViewModel; | ||
} | ||
|
||
public TModel ToServiceModel(TViewModel viewModel) | ||
{ | ||
//Todo: return not null | ||
if (viewModel == null) | ||
return null; | ||
|
||
var model = Activator.CreateInstance<TModel>(); | ||
|
||
model.Id = viewModel.Id; | ||
model.ExternalId = viewModel.ExternalId; | ||
model.AddedDate = viewModel.AddedDate ?? default(long); | ||
model.ModifiedDate = viewModel.ModifiedDate ?? default(long); | ||
model.DeletedDate = viewModel.DeletedDate ?? DateTime.Now.ConvertToUnixTime(); | ||
model.IsDeleted = viewModel.IsDeleted ?? default(bool); | ||
|
||
return model; | ||
} | ||
|
||
public IReadOnlyCollection<TViewModel> ToViewModel(IReadOnlyCollection<TModel> models) | ||
{ | ||
if (models.Count == 0) | ||
{ | ||
return Array.Empty<TViewModel>(); | ||
} | ||
|
||
var subscription = new TViewModel[models.Count]; | ||
var i = 0; | ||
foreach (var model in models) | ||
{ | ||
subscription[i] = ToViewModel(model); | ||
++i; | ||
} | ||
|
||
return new ReadOnlyCollection<TViewModel>(subscription); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Services/e-sender/O2NextGen.ESender.Api/Models/EmailRequestViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
namespace O2NextGen.ESender.Api.Models | ||
{ | ||
public interface IViewModel | ||
{ | ||
long Id { get; set; } | ||
string ExternalId { get; set; } | ||
long? ModifiedDate { get; set; } | ||
long? AddedDate { get; set; } | ||
long? DeletedDate { get; set; } | ||
bool? IsDeleted { get; set; } | ||
} | ||
public class EmailRequestViewModel: IViewModel | ||
{ | ||
public long Id { get; set; } | ||
public string ExternalId { get; set; } | ||
public long? ModifiedDate { get; set; } | ||
public long? AddedDate { get; set; } | ||
public long? DeletedDate { get; set; } | ||
public bool? IsDeleted { get; set; } | ||
public string From { get; set; } | ||
public string To { get; set; } | ||
public string Body { get; set; } | ||
public string Subject { get; set; } | ||
} | ||
} | ||
|
13 changes: 0 additions & 13 deletions
13
src/Services/e-sender/O2NextGen.ESender.Api/Models/MailRequestViewModel.cs
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/Services/e-sender/O2NextGen.ESender.Api/Views/Board/Create.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Services/e-sender/O2NextGen.ESender.Api/Views/Board/Detail.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Services/e-sender/O2NextGen.ESender.Api/Views/Board/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/Services/e-sender/O2NextGen.ESender.Business/Models/EmailRequest.cs
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/Services/e-sender/O2NextGen.ESender.Business/Models/EmailRequestModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace O2NextGen.ESender.Business.Models | ||
{ | ||
public class EmailRequestModel: IBaseModel | ||
{ | ||
public long Id { get; set; } | ||
public string ExternalId { get; set; } | ||
public string From { get; set; } | ||
public string To { get; set; } | ||
public string Subject { get; set; } | ||
public string Body { get; set; } | ||
public long AddedDate { get; set; } | ||
public long DeletedDate { get; set; } | ||
public bool IsDeleted { get; set; } | ||
public long ModifiedDate { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Services/e-sender/O2NextGen.ESender.Business/Models/IBaseModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace O2NextGen.ESender.Business.Models | ||
{ | ||
public interface IBaseModel | ||
{ | ||
long Id { get; set; } | ||
string ExternalId { get; set; } | ||
long ModifiedDate { get; set; } | ||
long AddedDate { get; set; } | ||
long DeletedDate { get; set; } | ||
bool IsDeleted { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.