public void CreateAttachment_PassData_GetAttachmentModel()
        {
            //arrange
            var options = new DbContextOptionsBuilder <AttachmentDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateAttachment_PassData_GetAttachmentModel")
                          .Options;
            //act
            AttachmentModel result;

            using (var context = new AttachmentDbContext(options))
            {
                var service = new SqlServerAttachmenBusiness(context);
                result = service.CreateAttachmentTemporarily(new TemporaryAttachmentKeyModel {
                    EntityName = "x", FieldName = "y", Token = "z"
                });
            }
            //assert
            Assert.IsNotNull(result);
            using (var context = new AttachmentDbContext(options))
            {
                var item = context.Attachments.SingleOrDefault(x => x.Id == result.AttachmentId);
                Assert.IsNotNull(item);
                Assert.AreEqual("x", item.EntityName);
                Assert.AreEqual("y", item.FieldName);
                Assert.AreEqual("z", item.Token);
                Assert.AreEqual(null, item.EntityId);
            }
        }
        public void CreateAttachment_Token_PassInvalidArgument_GetException(string entity, string field, string token)
        {
            //arrange
            var options = new DbContextOptionsBuilder <AttachmentDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateAttachment_PassNull_GetException")
                          .Options;

            //act
            using (var context = new AttachmentDbContext(options))
            {
                var service = new SqlServerAttachmenBusiness(context);
                Assert.Throws <ArgumentNullException>(() =>
                {
                    //act
                    service.CreateAttachmentTemporarily(new TemporaryAttachmentKeyModel {
                        EntityName = entity, FieldName = field, Token = token
                    });
                });
            }
        }
示例#3
0
 public static void UseSqlServerAttachmenBusiness(this AttachmentServiceConfigurationOptions _this, string connectionString)
 {
     _this.services.AddScoped <IAttachmentBusiness>((s) => SqlServerAttachmenBusiness.SqlServerAttachmenBusinessFactory(connectionString));
 }