public async Task <Vial> CreateVialAsync(string vialID, VialType type) { // TODO:is it right here where validation is that check existing vial ??? var vial = await db.Vials.FindAsync(vialID); if (vial != null) { return(null); } vial = new Vial() { VialID = vialID, BoxID = null, IsOut = true, VialType = type, Position = null }; db.Vials.Add(vial); var affected = await db.SaveChangesAsync(); if (affected != 0) { return(vial); } return(null); }
public async Task TestCreateVialAsync() { var newVialType = new VialType() { Name = "TestVialType", }; context.VialTypes.Add(newVialType); context.SaveChanges(); var createdVial = await repository.CreateVialAsync(vialID : "TestVial", type : newVialType); Assert.NotNull(createdVial); Assert.True(createdVial.VialID == "TestVial"); Assert.True(createdVial.VialTypeName == newVialType.Name); createdVial = await repository.CreateVialAsync(vialID : "TestVial", type : newVialType); Assert.Null(createdVial); }