public async Task <int> Create(WebsiteProxy websiteProxy) { WebsiteValidator.ValidateOnUpdateOrCreate(websiteProxy); var id = await WebsiteRepository.Create(websiteProxy); return(id); }
public void ValidateOnPatch(WebsiteProxy websiteProxy) { ValidateWebsiteUrl(websiteProxy.Url, true); ValidateWebsiteName(websiteProxy.Name, true); ValidateCategory(websiteProxy.CategoryId, true); LoginValidator.Validate(websiteProxy.Logins?.ToArray(), true); FieldValidator.Validate(websiteProxy.Fields?.ToArray(), true); WebsiteHomepageSnapshotValidator.Validate(websiteProxy.HomepageSnapshot, true); }
public void ValidateOnUpdateOrCreate(WebsiteProxy websiteProxy) { ValidateWebsiteUrl(websiteProxy.Url); ValidateWebsiteName(websiteProxy.Name); ValidateCategory(websiteProxy.CategoryId); LoginValidator.Validate(websiteProxy.Logins?.ToArray(), false); FieldValidator.Validate(websiteProxy.Fields?.ToArray(), false); WebsiteHomepageSnapshotValidator.Validate(websiteProxy.HomepageSnapshot, false); }
public async Task Test_create() { var testProxy = new WebsiteProxy() { Name = "stackoverflow", Url = "https://stackoverflow.com", CategoryId = WebsiteCategoryEnum.None, HomepageSnapshot = new WebsiteHomepageSnapshotProxy() { Image = new byte[] { 42, 34, 64, 64 } }, Logins = new Collection <WebsiteLoginProxy>() { new WebsiteLoginProxy() { Email = "*****@*****.**", Password = "******" } }, Fields = new Collection <WebsiteFieldProxy>() { new WebsiteFieldProxy() { FieldName = "Field Name", FieldValue = "Field Value" } } }; var controller = await GetWebsiteController(); var id = await controller.Create(testProxy); Assert.True(id > 100); var addedWebsiteProxy = await controller.Get(id); Assert.Equal(id, addedWebsiteProxy.Id); Assert.Equal(testProxy.Name, addedWebsiteProxy.Name); Assert.Equal(testProxy.Url, addedWebsiteProxy.Url); Assert.Equal(testProxy.CategoryId, addedWebsiteProxy.CategoryId); Assert.NotNull(addedWebsiteProxy.HomepageSnapshot); Assert.Equal(testProxy.HomepageSnapshot.Image, addedWebsiteProxy.HomepageSnapshot.Image); Assert.NotNull(addedWebsiteProxy.Logins); Assert.Equal(testProxy.Logins.Count, addedWebsiteProxy.Logins.Count); Assert.Equal(testProxy.Logins.First().Email, addedWebsiteProxy.Logins.First().Email); Assert.Equal(testProxy.Logins.First().Password, addedWebsiteProxy.Logins.First().Password); Assert.NotNull(addedWebsiteProxy.Fields); Assert.Equal(testProxy.Fields.Count, addedWebsiteProxy.Fields.Count); Assert.Equal(testProxy.Fields.First().FieldName, addedWebsiteProxy.Fields.First().FieldName); Assert.Equal(testProxy.Fields.First().FieldValue, addedWebsiteProxy.Fields.First().FieldValue); }
public async Task <WebsiteProxy> Patch(WebsiteProxy websiteProxy) { WebsiteValidator.ValidateOnPatch(websiteProxy); var updatedObject = await WebsiteRepository.Patch(websiteProxy); if (updatedObject is null) { throw new NotFoundError($"Update Failed. Website with id {websiteProxy.Id} not found"); } return(updatedObject); }
public void Update(WebsiteProxy srcProxy, Website dest) { var src = Create(srcProxy); AutoMapper.Map(src, dest); RemoveMissingFields(dest.Fields, src.Fields); RemoveMissingLogins(dest.Logins, src.Logins); UpdateFields(dest.Fields, src.Fields); UpdateLogins(dest.Logins, src.Logins); AddNewFields(dest.Fields, src.Fields); AddNewLogins(dest.Logins, src.Logins); }
public async Task <int> Create(WebsiteProxy websiteProxy) { if (websiteProxy is null) { throw new NullReferenceException($"{nameof(websiteProxy)} param cannot be null"); } var websiteEntity = EntityMapper.Create(websiteProxy); await DbContext.Website.AddAsync(websiteEntity); await DbContext.SaveChangesAsync(); return(websiteEntity.Id); }
public async Task Test_update() { var controller = await GetWebsiteController(); var proxyToUpdate = new WebsiteProxy(); proxyToUpdate.Id = 1; proxyToUpdate.Name = "Website 0"; proxyToUpdate.Url = @"https://github.com/"; proxyToUpdate.HomepageSnapshot = new WebsiteHomepageSnapshotProxy() { Image = new byte[] { 32, 43, 64, 54 } }; proxyToUpdate.CategoryId = WebsiteCategoryEnum.Business; proxyToUpdate.Logins = new Collection <WebsiteLoginProxy>() { new WebsiteLoginProxy() { Email = $"*****@*****.**", Password = "******" } }; proxyToUpdate.Fields = null; var updatedProxy = await controller.Update(proxyToUpdate); Assert.Equal(proxyToUpdate.Name, updatedProxy.Name); Assert.Equal(proxyToUpdate.Url, updatedProxy.Url); Assert.Equal(proxyToUpdate.CategoryId, updatedProxy.CategoryId); Assert.NotNull(updatedProxy.HomepageSnapshot); Assert.NotNull(updatedProxy.HomepageSnapshot.Image); Assert.NotNull(updatedProxy.Logins); Assert.Equal(proxyToUpdate.Logins.Count, proxyToUpdate.Logins.Count); var checkOldEmail = !updatedProxy.Logins .Any(x => x.Email == "*****@*****.**"); Assert.True(checkOldEmail); var checkNewEmail = updatedProxy.Logins .Any(x => x.Email == "*****@*****.**" && x.Password == "ddd"); Assert.True(checkNewEmail); Assert.NotNull(updatedProxy.Fields); Assert.Equal(0, updatedProxy.Fields.Count); }
public async Task <WebsiteProxy> Update(WebsiteProxy websiteProxy) { if (websiteProxy.Id == 0) { throw new NotFoundError($"Update Failed. Website {websiteProxy.Id} not provided"); } WebsiteValidator.ValidateOnUpdateOrCreate(websiteProxy); var updatedObject = await WebsiteRepository.Update(websiteProxy); if (updatedObject is null) { throw new NotFoundError($"Update Failed. Website with id {websiteProxy.Id} not found"); } return(updatedObject); }
public async Task Test_patch() { var controller = await GetWebsiteController(); var proxyToPatch = new WebsiteProxy() { Id = 1, Name = "New Name", Logins = new Collection <WebsiteLoginProxy>() { new WebsiteLoginProxy() { Email = "*****@*****.**", Password = "******" }, new WebsiteLoginProxy() { Email = "*****@*****.**", Password = "******" } } }; var patchedProxy = await controller.Patch(proxyToPatch); Assert.Equal(proxyToPatch.Name, patchedProxy.Name); Assert.Equal("http:\\\\url0.com", patchedProxy.Url); Assert.Equal(WebsiteCategoryEnum.Blog, patchedProxy.CategoryId); Assert.NotNull(patchedProxy.HomepageSnapshot); Assert.NotNull(patchedProxy.HomepageSnapshot.Image); Assert.NotNull(patchedProxy.Logins); Assert.Equal(2, patchedProxy.Logins.Count); var checkOldEmail = patchedProxy.Logins .Any(x => x.Email == "*****@*****.**" && x.Password == "new password"); Assert.True(checkOldEmail); var checkNewEmail = patchedProxy.Logins .Any(x => x.Email == "*****@*****.**" && x.Password == "fdsfsdfsd"); Assert.True(checkNewEmail); Assert.NotNull(patchedProxy.Fields); Assert.Equal(1, patchedProxy.Fields.Count); Assert.Equal("Website 0 Field", patchedProxy.Fields.First().FieldName); }
public void Patch(WebsiteProxy srcProxy, Website dest) { var src = Create(srcProxy); var categoryId = dest.CategoryId; AutoMapper.Map(src, dest); if (!srcProxy.CategoryId.HasValue) { dest.CategoryId = categoryId; } UpdateFields(dest.Fields, src.Fields); UpdateLogins(dest.Logins, src.Logins); AddNewFields(dest.Fields, src.Fields); AddNewLogins(dest.Logins, src.Logins); }
public async Task <WebsiteProxy> Update(WebsiteProxy websiteProxy) { if (websiteProxy is null) { throw new NullReferenceException($"{nameof(websiteProxy)} param cannot be null"); } var websiteEntity = await GetInternal(websiteProxy.Id); if (websiteEntity is null) { return(null); } EntityMapper.Update(websiteProxy, websiteEntity); await DbContext.SaveChangesAsync(); return(EntityMapper.Map(websiteEntity).FirstOrDefault()); }
public async Task Test_Patch_Homepage_Snapshot_Image_of_Website_entity_from_Proxy() { var entityMapper = await GetEntityMapper(); var testProxy = TestProxy; var websiteEntity = entityMapper.Create(testProxy); testProxy = new WebsiteProxy { Name = "new name", HomepageSnapshot = new WebsiteHomepageSnapshotProxy() { Image = new byte[] { 1, 2 } } }; Assert.Null(testProxy.Logins); Assert.Null(testProxy.Fields); var id = websiteEntity.Id; var url = websiteEntity.Url; var categoryId = websiteEntity.CategoryId; var statusId = websiteEntity.StatusId; int loginsCount = websiteEntity.Logins.Count; int loginsFieldsCount = websiteEntity.Fields.Count; entityMapper.Patch(testProxy, websiteEntity); Assert.Equal(testProxy.Name, websiteEntity.Name); Assert.NotNull(websiteEntity.Logins); Assert.NotNull(websiteEntity.Fields); Assert.Equal(id, websiteEntity.Id); Assert.Equal(url, websiteEntity.Url); Assert.Equal(categoryId, websiteEntity.CategoryId); Assert.Equal(statusId, websiteEntity.StatusId); Assert.Equal(loginsCount, websiteEntity.Logins.Count); Assert.Equal(loginsFieldsCount, websiteEntity.Fields.Count); }
public Website Create(WebsiteProxy websiteProxy) { return(AutoMapper.Map <Website>(websiteProxy)); }
public async Task <int> Create([FromBody] WebsiteProxy website) { return(await WebsiteDataService.Create(website)); }
public async Task <WebsiteProxy> Update([FromBody] WebsiteProxy website) { return(await WebsiteDataService.Update(website)); }
public async Task <WebsiteProxy> Patch([FromBody] WebsiteProxy website) { return(await WebsiteDataService.Patch(website)); }