コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }