Interface Implementation Issue - asp.net

I Have a Base Interface Like this
public interface IHRMISBaseConnector
{
IHRMISEmployeeConnector EmployeeConnector { get ; set; }
}
And i have one more interface like this
public interface IHRMISEmployeeConnector
{
String Add(EmployeeDetails e);
Boolean Update(EmployeeDetails e);
Boolean Delete(int id);
}
I want implement IHRMISBaseConnector in this class DDWEDocumentOperations
How can i implement ? Please let me know if anybody knows it

Something like this should help you:
class FakeImplementationOfEmployeeConnector : IHRMISEmployeeConnector
{
public string Add(EmployeeDetails e)
{
//...
}
public bool Update(EmployeeDetails e)
{
//...
}
public bool Delete(int id)
{
//...
}
}
class DDWEDocumentOperations : IHRMISBaseConnector
{
IHRMISEmployeeConnector employeeConnector = new FakeImplementationOfEmployeeConnector();
public IHRMISEmployeeConnector EmployeeConnector
{
get
{
return employeeConnector;
}
set
{
employeeConnector = value;
}
}
}

Here is an example:
public class DDWEDocumentOperations : IHRMISBaseConnector
{
private IHRMISEmployeeConnector _employeeConnector;
public IHRMISEmployeeConnector EmployeeConnector
{
get { return _employeeConnector; }
set { _employeeConnector = value; }
}
}

Related

What's the use case of p:collector vs custom wrapper class?

I didn't know about p:collector. I created this custom abstract class:
abstract public class Wrapper<T> {
protected Integer number;
protected List<T> list;
protected Class<T> klass;
public Wrapper() {
this.setList(new ArrayList<T>());
}
public void setListNumber(Integer number) {
Class<T> klass = this.getKlass();
List<T> list = this.getList();
ListUtil.setSize((ArrayList<T>) list, number, klass);
}
public void add() {
List<T> list = this.getList();
Class<T> klass = this.getKlass();
try {
list.add(klass.newInstance());
}
catch (InstantiationException e) {
throw new InstantiationUncheckedException(e);
}
catch (IllegalAccessException e) {
throw new IllegalAccessUncheckedException(e);
}
}
public void remove(int i) {
List<T> list = this.getList();
list.remove(i);
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public Class<T> getKlass() {
return klass;
}
public void setKlass(Class<T> klass) {
this.klass = klass;
}
}
and I usually use it this way:
public class Things extends Wrapper<Thing> {
public Things() {
super();
this.setKlass(Thing.class);
}
#Override
public String toString() {
return "Things [number=" + number + ", list=" + list + "]";
}
}
and in the view, for example:
<ui:repeat varStatus="status" var="thing" value="#{bean.things.list}">
and
<p:commandButton
value="Add"
action="#{bean.things.add()}"
immediate="true"
/>
<p:commandButton
value="❌"
action="#{bean.licenze.remove(status.index)}"
immediate="true"
/>
p:collector collector could do this better/with less code?
p:collector was removed in PrimeFaces 11 after being deprecated in 10, so better not use it if you ever want to upgrade.

service doesn't start in sysoperation framework

Below are shown my classes of sysOperation framework, my problem is when i open the dialog and i press OK , nothing happens, what's wrong with this code?
My service class:
class ProdutionFLowsService extends SysOperationServiceBase
{
ProductionFlowId idOfCopy;
int copyToDo;
ProdTable prodTable;
public void process(ProdutionFLowsContract _contract)
{
this.getPromptParameters(_contract);
select firstonly ProdId
from prodTable
order by ProdId
where prodTable.ProductionFlowId == this.idOfCopy;
this.insertInProdTable();
}
public void insertInProdTable()
{
ProdTable _prodTable;
while(copyToDo > 0)
{
buf2Buf(prodTable,_prodTable);
_prodTable.RecId = 0;
_prodTable.ProdId = _prodTable.Type().initProdId(true);
_prodTable.GAP035ProductionFlowId = _prodTable.ProductionFlowId;
_prodTable.insert();
copyToDo--;
}
}
public void getPromptParameters(ProdutionFLowsContract _contract)
{
copyToDo = _contract.parmCopyToDo();
idOfCopy = _contract.parmidOfCopy();
}
}
My controller class:
class ProdutionFLowsController extends SysOperationServiceController
{
public void new()
{
super();
super(classStr(ProdutionFLowsService), methodStr(ProdutionFLowsService, process), SysOperationExecutionMode::Synchronous);
this.parmDialogCaption("TODO");
}
public static void main(Args _args)
{
ProdutionFLowsController controller = new ProdutionFLowsController();
controller.parmArgs(_args);
controller.startOperation();
}
}
My Contract Class:
[DataContractAttribute]
class ProdutionFLowsContract implements SysOperationInitializable,SysOperationValidatable
{
ProductionFlowId idOfCopy;
int copyToDo;
public void initialize()
{
idOfCopy = "";
copyToDo = 0;
}
[DataMemberAttribute("idOfCopy"),SysOperationLabelAttribute(literalStr("TODO(Id)")),SysOperationDisplayOrderAttribute("1")]
public ProductionFlowId parmidOfCopy(ProductionFlowId _idOfCopy = idOfCopy)
{
idOfCopy = _idOfCopy;
return idOfCopy;
}
[DataMemberAttribute("copyToDo"),SysOperationLabelAttribute(literalStr("copyToDo(Copy)")),SysOperationDisplayOrderAttribute("2")]
public int parmCopyToDo(int _copyToDo = copyToDo)
{
copyToDo = _copyToDo;
return copyToDo;
}
public boolean validate()
{
return false;
}
}
Your contract validation always fails because it always returns false and doesn't show any error in the infolog:
public boolean validate()
{
return false;
}
Try to replace return false with return true or to remove SysOperationValidatable and validate method altogether.

update parent child table [duplicate]

This question already has an answer here:
GridView's UpdateMethod not firing
(1 answer)
update linq related table
Closed 9 years ago.
I have two table, they are parent child. testtypes(Id,Name), testusers(Id,TypeId,Name)
i want update them in gridview. testusers (name filed) was updated but testTypes(testtype.Name field) doesn't update.
there is no exception. (i check the e.exception == null variable in GridviewUpdated handler.)
i'm really confuesd! it's so strange. i think vs 2012 has bug!
here's my markup and code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Ahooratech.WebForm4" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="gv" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="LinqDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="testtype.Name" HeaderText="mytypid" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Ahooratech.DAL.DataClasses1DataContext" EnableUpdate="True" EntityTypeName="" TableName="testusers">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
and:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Ahooratech
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
gv.rowUpdated += handler;
}
void gv_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.exception == null)
{
resultlbl.text = "Update seccessfully";// i get this message and name update in db
}
}
}
}
and DAL:
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="AhooraTechdb")]
public partial class DataClasses1DataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
public DataClasses1DataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["AhooraTechdbConnectionString1"].ConnectionString, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<AdminUser> AdminUsers
{
get
{
return this.GetTable<AdminUser>();
}
}
public System.Data.Linq.Table<WishProduct> WishProducts
{
get
{
return this.GetTable<WishProduct>();
}
}
public System.Data.Linq.Table<Advertisement> Advertisements
{
get
{
return this.GetTable<Advertisement>();
}
}
public System.Data.Linq.Table<aspnet_Application> aspnet_Applications
{
get
{
return this.GetTable<aspnet_Application>();
}
}
public System.Data.Linq.Table<aspnet_Membership> aspnet_Memberships
{
get
{
return this.GetTable<aspnet_Membership>();
}
}
public System.Data.Linq.Table<aspnet_SchemaVersion> aspnet_SchemaVersions
{
get
{
return this.GetTable<aspnet_SchemaVersion>();
}
}
public System.Data.Linq.Table<aspnet_User> aspnet_Users
{
get
{
return this.GetTable<aspnet_User>();
}
}
public System.Data.Linq.Table<BillingType> BillingTypes
{
get
{
return this.GetTable<BillingType>();
}
}
public System.Data.Linq.Table<BoolValue> BoolValues
{
get
{
return this.GetTable<BoolValue>();
}
}
public System.Data.Linq.Table<ContainerItem> ContainerItems
{
get
{
return this.GetTable<ContainerItem>();
}
}
public System.Data.Linq.Table<Container> Containers
{
get
{
return this.GetTable<Container>();
}
}
public System.Data.Linq.Table<Country> Countries
{
get
{
return this.GetTable<Country>();
}
}
public System.Data.Linq.Table<DeliveryTimeType> DeliveryTimeTypes
{
get
{
return this.GetTable<DeliveryTimeType>();
}
}
public System.Data.Linq.Table<DeliveryType> DeliveryTypes
{
get
{
return this.GetTable<DeliveryType>();
}
}
public System.Data.Linq.Table<DescriptiveValue> DescriptiveValues
{
get
{
return this.GetTable<DescriptiveValue>();
}
}
public System.Data.Linq.Table<DiscountCode> DiscountCodes
{
get
{
return this.GetTable<DiscountCode>();
}
}
public System.Data.Linq.Table<DiscountCodesPrice> DiscountCodesPrices
{
get
{
return this.GetTable<DiscountCodesPrice>();
}
}
public System.Data.Linq.Table<DiscountcodesProduct> DiscountcodesProducts
{
get
{
return this.GetTable<DiscountcodesProduct>();
}
}
public System.Data.Linq.Table<DiscountCodesUser> DiscountCodesUsers
{
get
{
return this.GetTable<DiscountCodesUser>();
}
}
public System.Data.Linq.Table<DiscountType> DiscountTypes
{
get
{
return this.GetTable<DiscountType>();
}
}
public System.Data.Linq.Table<MeasurmentValue> MeasurmentValues
{
get
{
return this.GetTable<MeasurmentValue>();
}
}
public System.Data.Linq.Table<ProductImage> ProductImages
{
get
{
return this.GetTable<ProductImage>();
}
}
public System.Data.Linq.Table<ProductOption> ProductOptions
{
get
{
return this.GetTable<ProductOption>();
}
}
public System.Data.Linq.Table<ProductProductOption> ProductProductOptions
{
get
{
return this.GetTable<ProductProductOption>();
}
}
public System.Data.Linq.Table<Product> Products
{
get
{
return this.GetTable<Product>();
}
}
public System.Data.Linq.Table<ProductsCat> ProductsCats
{
get
{
return this.GetTable<ProductsCat>();
}
}
public System.Data.Linq.Table<ProductsDescriptionImage> ProductsDescriptionImages
{
get
{
return this.GetTable<ProductsDescriptionImage>();
}
}
public System.Data.Linq.Table<ProductsPeripheralProduct> ProductsPeripheralProducts
{
get
{
return this.GetTable<ProductsPeripheralProduct>();
}
}
public System.Data.Linq.Table<ProductsProperty> ProductsProperties
{
get
{
return this.GetTable<ProductsProperty>();
}
}
public System.Data.Linq.Table<ProductsRelatedProduct> ProductsRelatedProducts
{
get
{
return this.GetTable<ProductsRelatedProduct>();
}
}
public System.Data.Linq.Table<Property> Properties
{
get
{
return this.GetTable<Property>();
}
}
public System.Data.Linq.Table<PropertyCat> PropertyCats
{
get
{
return this.GetTable<PropertyCat>();
}
}
public System.Data.Linq.Table<RetrurnedOrder> RetrurnedOrders
{
get
{
return this.GetTable<RetrurnedOrder>();
}
}
public System.Data.Linq.Table<ReturnCause> ReturnCauses
{
get
{
return this.GetTable<ReturnCause>();
}
}
public System.Data.Linq.Table<ShippingType> ShippingTypes
{
get
{
return this.GetTable<ShippingType>();
}
}
public System.Data.Linq.Table<ShortDescriptiveValue> ShortDescriptiveValues
{
get
{
return this.GetTable<ShortDescriptiveValue>();
}
}
public System.Data.Linq.Table<SqlDataType> SqlDataTypes
{
get
{
return this.GetTable<SqlDataType>();
}
}
public System.Data.Linq.Table<State> States
{
get
{
return this.GetTable<State>();
}
}
public System.Data.Linq.Table<StatesShippingType> StatesShippingTypes
{
get
{
return this.GetTable<StatesShippingType>();
}
}
public System.Data.Linq.Table<StockStateType> StockStateTypes
{
get
{
return this.GetTable<StockStateType>();
}
}
public System.Data.Linq.Table<test> tests
{
get
{
return this.GetTable<test>();
}
}
public System.Data.Linq.Table<Unit> Units
{
get
{
return this.GetTable<Unit>();
}
}
public System.Data.Linq.Table<UserRequestProduct> UserRequestProducts
{
get
{
return this.GetTable<UserRequestProduct>();
}
}
public System.Data.Linq.Table<User> Users
{
get
{
return this.GetTable<User>();
}
}
public System.Data.Linq.Table<Warranty> Warranties
{
get
{
return this.GetTable<Warranty>();
}
}
public System.Data.Linq.Table<SideBarMenuItem> SideBarMenuItems
{
get
{
return this.GetTable<SideBarMenuItem>();
}
}
public System.Data.Linq.Table<OrderItem> OrderItems
{
get
{
return this.GetTable<OrderItem>();
}
}
public System.Data.Linq.Table<UserAddress> UserAddresses
{
get
{
return this.GetTable<UserAddress>();
}
}
public System.Data.Linq.Table<Basket> Baskets
{
get
{
return this.GetTable<Basket>();
}
}
public System.Data.Linq.Table<ElseCost> ElseCosts
{
get
{
return this.GetTable<ElseCost>();
}
}
public System.Data.Linq.Table<OrderStatuse> OrderStatuses
{
get
{
return this.GetTable<OrderStatuse>();
}
}
public System.Data.Linq.Table<ShipmentStatuse> ShipmentStatuses
{
get
{
return this.GetTable<ShipmentStatuse>();
}
}
public System.Data.Linq.Table<ConfirmStatuse> ConfirmStatuses
{
get
{
return this.GetTable<ConfirmStatuse>();
}
}
public System.Data.Linq.Table<PaymentStatuse> PaymentStatuses
{
get
{
return this.GetTable<PaymentStatuse>();
}
}
public System.Data.Linq.Table<Order> Orders
{
get
{
return this.GetTable<Order>();
}
}
public System.Data.Linq.Table<testtype> testtypes
{
get
{
return this.GetTable<testtype>();
}
}
public System.Data.Linq.Table<testuser> testusers
{
get
{
return this.GetTable<testuser>();
}
}
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.FetchProperties")]
public ISingleResult<FetchPropertiesResult> FetchProperties([global::System.Data.Linq.Mapping.ParameterAttribute(Name="ProductId", DbType="Int")] System.Nullable<int> productId)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), productId);
return ((ISingleResult<FetchPropertiesResult>)(result.ReturnValue));
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.testtypes")]
public partial class testtype : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Id;
private string _Name;
private EntitySet<testuser> _testusers;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdChanging(int value);
partial void OnIdChanged();
partial void OnNameChanging(string value);
partial void OnNameChanged();
#endregion
public testtype()
{
this._testusers = new EntitySet<testuser>(new Action<testuser>(this.attach_testusers), new Action<testuser>(this.detach_testusers));
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", DbType="Int NOT NULL", IsPrimaryKey=true)]
public int Id
{
get
{
return this._Id;
}
set
{
if ((this._Id != value))
{
this.OnIdChanging(value);
this.SendPropertyChanging();
this._Id = value;
this.SendPropertyChanged("Id");
this.OnIdChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="NVarChar(50)")]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="testtype_testuser", Storage="_testusers", ThisKey="Id", OtherKey="TypeId")]
public EntitySet<testuser> testusers
{
get
{
return this._testusers;
}
set
{
this._testusers.Assign(value);
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void attach_testusers(testuser entity)
{
this.SendPropertyChanging();
entity.testtype = this;
}
private void detach_testusers(testuser entity)
{
this.SendPropertyChanging();
entity.testtype = null;
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.testusers")]
public partial class testuser : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Id;
private string _Name;
private System.Nullable<int> _TypeId;
private EntityRef<testtype> _testtype;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdChanging(int value);
partial void OnIdChanged();
partial void OnNameChanging(string value);
partial void OnNameChanged();
partial void OnTypeIdChanging(System.Nullable<int> value);
partial void OnTypeIdChanged();
#endregion
public testuser()
{
this._testtype = default(EntityRef<testtype>);
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", DbType="Int NOT NULL", IsPrimaryKey=true)]
public int Id
{
get
{
return this._Id;
}
set
{
if ((this._Id != value))
{
this.OnIdChanging(value);
this.SendPropertyChanging();
this._Id = value;
this.SendPropertyChanged("Id");
this.OnIdChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="NVarChar(50)")]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TypeId", DbType="Int")]
public System.Nullable<int> TypeId
{
get
{
return this._TypeId;
}
set
{
if ((this._TypeId != value))
{
if (this._testtype.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnTypeIdChanging(value);
this.SendPropertyChanging();
this._TypeId = value;
this.SendPropertyChanged("TypeId");
this.OnTypeIdChanged();
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="testtype_testuser", Storage="_testtype", ThisKey="TypeId", OtherKey="Id", IsForeignKey=true)]
public testtype testtype
{
get
{
return this._testtype.Entity;
}
set
{
testtype previousValue = this._testtype.Entity;
if (((previousValue != value)
|| (this._testtype.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._testtype.Entity = null;
previousValue.testusers.Remove(this);
}
this._testtype.Entity = value;
if ((value != null))
{
value.testusers.Add(this);
this._TypeId = value.Id;
}
else
{
this._TypeId = default(Nullable<int>);
}
this.SendPropertyChanged("testtype");
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public partial class FetchPropertiesResult
{
private int _ProdPropId;
private string _propertyName;
private string _UnitName;
private string _propertyCatName;
private string _sqlType;
private string _stringVal;
private string _shortStringVal;
private System.Nullable<int> _measurmentVal;
private System.Nullable<bool> _boolVal;
private int _OrderId;
public FetchPropertiesResult()
{
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ProdPropId", DbType="Int NOT NULL")]
public int ProdPropId
{
get
{
return this._ProdPropId;
}
set
{
if ((this._ProdPropId != value))
{
this._ProdPropId = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_propertyName", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string propertyName
{
get
{
return this._propertyName;
}
set
{
if ((this._propertyName != value))
{
this._propertyName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UnitName", DbType="NVarChar(50)")]
public string UnitName
{
get
{
return this._UnitName;
}
set
{
if ((this._UnitName != value))
{
this._UnitName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_propertyCatName", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string propertyCatName
{
get
{
return this._propertyCatName;
}
set
{
if ((this._propertyCatName != value))
{
this._propertyCatName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_sqlType", DbType="NVarChar(20) NOT NULL", CanBeNull=false)]
public string sqlType
{
get
{
return this._sqlType;
}
set
{
if ((this._sqlType != value))
{
this._sqlType = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_stringVal", DbType="NVarChar(MAX)")]
public string stringVal
{
get
{
return this._stringVal;
}
set
{
if ((this._stringVal != value))
{
this._stringVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_shortStringVal", DbType="NVarChar(100)")]
public string shortStringVal
{
get
{
return this._shortStringVal;
}
set
{
if ((this._shortStringVal != value))
{
this._shortStringVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_measurmentVal", DbType="Int")]
public System.Nullable<int> measurmentVal
{
get
{
return this._measurmentVal;
}
set
{
if ((this._measurmentVal != value))
{
this._measurmentVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_boolVal", DbType="Bit")]
public System.Nullable<bool> boolVal
{
get
{
return this._boolVal;
}
set
{
if ((this._boolVal != value))
{
this._boolVal = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OrderId", DbType="Int NOT NULL")]
public int OrderId
{
get
{
return this._OrderId;
}
set
{
if ((this._OrderId != value))
{
this._OrderId = value;
}
}
}
}

Nunit tests on Response.Cache.VaryByHeader

I am doing some Unit testing with NUnit and NSubstitute on a function that uses HttpResponse, I know you can't mock these objects so I have created interfaces to represent them and some of there properties.
I'm having trouble understanding how to create an interface for Response.Cache.VaryByHeader
// This is my HttpResponse interface
public interface IHttpResponse
{
Stream Filter { get ; set; }
IHttpCachePolicy Cache { get; set; }
void AppendHeader(string name, string value);
}
// concrete httresponse
public class HttpResponseProxy : IHttpResponse
{
private HttpResponse _httpResponse;
public Stream Filter {
get {
return _httpResponse.Filter ?? new MemoryStream();
}
set { _httpResponse.Filter = value; }
}
public IHttpCachePolicy Cache
{
get { return new HttpCachePolicyProxy(_httpResponse.Cache); }
set { }
}
public HttpResponseProxy(HttpResponse httpResponse)
{
if (httpResponse == null)
{
throw new ArgumentNullException("httpResponse");
}
_httpResponse = httpResponse;
_httpResponse.Filter = httpResponse.Filter;
}
public void AppendHeader(string name, string value)
{
_httpResponse.AppendHeader(name, value);
}
}
// HttpCachePolicy interface
public interface IHttpCachePolicy
{
IHttpCacheVaryByHeaders VaryByHeaders { get; set; }
}
// concrete HttpCachePolicy
public class HttpCachePolicyProxy : IHttpCachePolicy
{
private HttpCachePolicy _httpCachePolicy;
public HttpCachePolicyProxy(HttpCachePolicy httpCachePolicy)
{
_httpCachePolicy = httpCachePolicy;
}
public IHttpCacheVaryByHeaders VaryByHeaders
{
get { return new HttpCacheVaryByHeadersProxy(_httpCachePolicy.VaryByHeaders as HttpCacheVaryByHeaders); }
set { }
}
}
public interface IHttpCacheVaryByHeaders
{
IHttpCacheVaryByHeaders HttpCacheVaryByHeaders { get; set; }
}
public class HttpCacheVaryByHeadersProxy : IHttpCacheVaryByHeaders
{
private HttpCacheVaryByHeaders _httpCacheVaryByHeaders;
public HttpCacheVaryByHeadersProxy(HttpCacheVaryByHeaders httpCacheVaryByHeaders)
{
_httpCacheVaryByHeaders = httpCacheVaryByHeaders;
}
public IHttpCacheVaryByHeaders HttpCacheVaryByHeaders
{
get { return new HttpCacheVaryByHeadersProxy(_httpCacheVaryByHeaders); }
set { }
}
}
This is the function i am actually testing:
public static void CompressPage(IHttpRequestGetCompressionMode getCompressionMode, IHttpResponse httpResponse)
{
string supportedCompression = getCompressionMode.GetClientSupportedCompressionMode();
if (supportedCompression != HttpHeaderValues.NoCompression)
{
switch (supportedCompression)
{
case HttpHeaderValues.DeflateCompression:
httpResponse.Filter = new DeflateStream(httpResponse.Filter, CompressionMode.Compress);
break;
case HttpHeaderValues.GZipCompression:
httpResponse.Filter = new GZipStream(httpResponse.Filter, CompressionMode.Compress);
break;
}
httpResponse.AppendHeader(HttpHeaderValues.ContentEncodingHeader, supportedCompression);
// this line is where i have the problem
httpResponse.Cache.VaryByHeaders[HttpHeaderValues.AcceptEncodingHeader] = true;
}
}
I'm getting "cannot apply index to an expression of type IHttpCacheVaryByHeaders" errors.
I have the interface for the response and cache but how do I represent VaryByHeaders in an interface and then use it in a concrete class?
The error seems to suggest that IHttpCacheVaryByHeaders does not have an indexer declared (e.g. bool this[string header] { get; set; }), but rather than implementing these wrappers yourself, try the HttpResponseWrapper and other System.Web.Abstractions. This will should make testing this stuff a lot easier. :)

Using a session wrapper for replacing direct call to session variables

I use a session wrapper like this:
public interface ISessionWrapper
{
// ...
CultureInfo Culture { get; set; }
}
public class SessionWrapper: ISessionWrapper
{
private T GetFromSession<T>(string key)
{
return (T)HttpContext.Current.Session[key];
}
private void SetInSession(string key, object value)
{
HttpContext.Current.Session[key] = value;
}
// ...
public CultureInfo Culture
{
get { return GetFromSession<CultureInfo>("Culture"); }
set { SetInSession("Culture", value); }
}
}
I can use this interface in my controller like this:
private readonly ISessionWrapper sessionWrapper = new SessionWrapper();
// ...
ci = new CultureInfo(langName);
sessionWrapper.Culture = ci;
But how can I access this wrapper in the view below to replace the (direct call to) session variable?
#switch (Session["Culture"].ToString())
{
case "fr":
// ...
case "uk":
// ...
}
You could make use of the base view:
public abstract class BaseViewPage : WebViewPage
{
public virtual ISessionWrapper SessionWrapper
{
get
{
return new SessionWrapper();
}
}
}
public abstract class BaseViewPage<TModel> : WebViewPage<TModel>
{
public virtual ISessionWrapper SessionWrapper
{
get
{
return new SessionWrapper();
}
}
}
your views will have access to SessionWrapper property.
Make sure to add pageBaseType="SessionWrapper" attribute to pages tag in web.config.

Resources